1

I have setup a WASM project using Rust and a game engine called Bevy to create graphics within a Svelte app. However, when I run the init() function generated by wasm-pack, it creates a canvas element for the graphics to be rendered into. Is there any way to make it render to a canvas I have created or to style the canvas it generates?

szammyboi
  • 25
  • 5

1 Answers1

2

You should be able to specify the canvas bevy should render to by setting the WindowDescriptor's canvas field

The docs say "If set, this selector will be used to find a matching html canvas element, rather than creating a new one. Uses the CSS selector format."

When you create the WindowDescriptor add the canvas selector as a field.

let window_descriptor = WindowDescriptor {
    canvas: "#mycanvas",
    ..default()
};
Joseph Chotard
  • 666
  • 5
  • 15