Skip to content

Commit

Permalink
Fix Animated Menu Background on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Sep 28, 2022
1 parent 6d93100 commit a709525
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion assets/ui/menu-background-zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const MenuBackground: BevyType<MenuBackground> = {
typeName: "jumpy::ui::main_menu::MainMenuBackground",
};

// This is a workaround for the fact that the Bevy types aren't getting set on WASM for some
// reason. Not a long-term solution, needs investigation.
const Time: BevyType<Time> = {
typeName: "bevy_time::time::Time",
};
const Transform: BevyType<Transform> = {
typeName: "bevy_transform::components::transform::Transform",
};

export default {
update() {
const time = world.resource(Time);
Expand All @@ -14,7 +23,7 @@ export default {
transform.scale.x = scale;
transform.scale.y = scale;

let offset = Math.sin(time.seconds_since_startup * 0.4 ) * 50;
let offset = Math.sin(time.seconds_since_startup * 0.4) * 50;
transform.translation.x = offset + 60;
transform.translation.y = offset * 0.2 - 20;
}
Expand Down
6 changes: 3 additions & 3 deletions src/scripting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ impl Plugin for ScriptingPlugin {
fn build(&self, app: &mut App) {
let custom_ops = ops::get_ops();

app.insert_non_send_resource(JsRuntimeConfig { custom_ops })
.add_plugin(JsScriptingPlugin)
.register_type::<Time>();
app.register_type::<Time>()
.insert_non_send_resource(JsRuntimeConfig { custom_ops })
.add_plugin(JsScriptingPlugin);
}
}

0 comments on commit a709525

Please sign in to comment.