Estoy tratando de hacer un GameEngine TypeScript muy básico, pero no puedo leer las propiedades de un error indefinido y no entiendo por qué.
Este es el error:
Uncaught TypeError: Cannot read properties of undefined (reading 'Update') at u (TSEngine.js:24:14)Mi código antes de convertir a javascript:
import Vector2 from "./class/Vector2.js"; import Square from "./class/Square.js"; export default class TSEngine { indexFileName: string; s: Square; v: Vector2; constructor(indexFileName: string) { this.indexFileName = indexFileName; } Vector2(x: number, y: number): Vector2 { this.v = new Vector2(x, y); return this.v; } Square(position: Vector2, size: number, color: string): Square { this.s = new Square(position, size, color); return this.s; } Update(toUpdate: () => void): void { if(toUpdate) { toUpdate(); } } u(deltaTime: number): void { this.Update(() => {}); requestAnimationFrame(this.u) } }Mi código después de convertir a javascript:
import Vector2 from "./class/Vector2.js"; import Square from "./class/Square.js"; export default class TSEngine { constructor(indexFileName) { this.indexFileName = indexFileName; } /*getBasePath(): string { return this.indexFileName; }*/ Vector2(x, y) { this.v = new Vector2(x, y); return this.v; } Square(position, size, color) { this.s = new Square(position, size, color); return this.s; } Update(toUpdate) { if (toUpdate) { toUpdate(); } } u(deltaTime) { this.Update(); /// it shows me the error here requestAnimationFrame(this.u); } }He intentado poner la función 'Actualizar' arriba pero no hace nada
Editar Estoy tratando de usar esta función así:
Engine.Update(() => { // the things to update })Puse un archivo console.log en la función Engine.Update pero solo se mostró una vez.