-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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");
},
);
},
);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Projects
Status
Todo