Skip to content

another "term is nil" error #201

@myuon

Description

@myuon
    js_fetch(
        "assets/rhb.json",
        fun (resp_id: i32) {
            let ref = JsRef::new(resp_id);
            let text = jsstring(ref);

            let j or err = Json::from_string(text);
            if err != nil {
                panic("Failed to parse JSON: {}", derive::to_string(err));
            }

            let sheet = Sheet::from_json(j!);

            let rhb = js_image_new();
            js_image_set_src(rhb, "assets/rhb.png");
            js_image_set_onload(
                rhb,
                fun () {
                    let frame = 0 - 1;
                    js_set_interval(
                        fun () {
                            frame = (frame + 1) % 8;
                            js_context_clear_rect(context, 0, 0, 600, 600);

                            let sprite = sheet.frames.("Run ({}).png".format((frame + 1).to_string()));
                            js_context_draw_image_with_sw_sh_dx_dy_dw_dh(
                                context,
                                rhb,
                                sprite.frame.x,
                                sprite.frame.y,
                                sprite.frame.w,
                                sprite.frame.h,
                                300,
                                300,
                                sprite.frame.w,
                                sprite.frame.h,
                            );
                        },
                        50,
                    );
                },
            );
            js_image_set_onerror(
                rhb,
                fun () {
                    panic("Image failed to load");
                },
            );
        },
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions