mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-11 02:29:25 +00:00
fix double rendering issue
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
engineCanvas.set(engineCanvas);
|
||||
width.set(canvas.width);
|
||||
height.set(canvas.height);
|
||||
// field.set_dimensions(canvas.width, canvas.height);
|
||||
|
||||
// setup entities
|
||||
listeners.forEach(async entity => {
|
||||
@@ -68,8 +69,6 @@
|
||||
|
||||
function tick(dt) {
|
||||
field.tick([], dt);
|
||||
let objects = JSON.parse(field.objects());
|
||||
render(objects, dt);
|
||||
}
|
||||
|
||||
function render(objects, dt) {
|
||||
@@ -93,8 +92,9 @@
|
||||
}
|
||||
|
||||
function handleResize () {
|
||||
width.set(window.innerWidth);
|
||||
height.set(window.innerHeight);
|
||||
// TODO: Resolution scaling needs to be implemented in wasm module.
|
||||
// width.set(window.innerWidth);
|
||||
// height.set(window.innerHeight);
|
||||
pixelRatio.set(window.devicePixelRatio);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -3,8 +3,8 @@ import {getContext, onMount} from "svelte";
|
||||
|
||||
export const engineCanvas = writable();
|
||||
export const engineCtx = writable();
|
||||
export const width = writable(window.innerWidth);
|
||||
export const height = writable(window.innerHeight);
|
||||
export const width = writable(800);
|
||||
export const height = writable(600);
|
||||
export const pixelRatio = writable(window.devicePixelRatio);
|
||||
|
||||
// A more convenient store for grabbing all game props
|
||||
|
||||
@@ -147,6 +147,12 @@ impl FieldWrapper {
|
||||
let json = json!(objs);
|
||||
serde_json::to_string(&json).unwrap()
|
||||
}
|
||||
|
||||
pub fn set_dimensions(&mut self, width_js: JsValue, height_js: JsValue) {
|
||||
let width = width_js.as_f64().unwrap();
|
||||
let height = height_js.as_f64().unwrap();
|
||||
self.field.set_dimensions(width as u16, height as u16);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -219,6 +219,11 @@ impl Field {
|
||||
pub fn objs(&self) -> Vec<&Rc<RefCell<Box<dyn GameObject>>>> {
|
||||
self.objs.iter().collect()
|
||||
}
|
||||
|
||||
pub fn set_dimensions(&mut self, width: u16, height: u16) {
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
impl DefaultGameObject {
|
||||
|
||||
Reference in New Issue
Block a user