I am writing an application to learn TypeScript. It works fine in Chrome, but I have a problem when working in Edge. I have this method:
set position(pos: Point) { const diffAsPoint = pos.minus(this.canvasPos); let diff: Vector2D = diffAsPoint.toVector2D(); // <--- this line if (diff instanceof Vector2D) { console.info("is a vector!"); } else { console.info("not a vector!"); }
I see that sometimes diff IS a Vector2D
and not an instance of Vector2D
. Obviously, when this happens, any operation on it leads to Object doesn't support property or method ...
The toVector2D
method toVector2D
simple:
toVector2D(): Vector2D { return new Vector2D(this.x, this.y); }
I don't know if this matters, but here is some background:
application - a game that runs in the game loop (60 frames per second - using window.requestAnimationFrame(() => this.animloop());
)
application works fine in Chrome
it doesn’t work fine in IE (it looks like another problem, but I couldn’t see what else when IE and debuggers work during the investigation)
uses the latest TypeScript (2.2.1)
this happens at a random point after starting, sometimes 2 seconds, sometimes 3 seconds
there are other places in the code where this happens, everything related to Point
and Vector2D
seems to be related to creating them in each frame (some problems disappear if I enter a field, rather than creating every frame)
I use AMD and requirejs
UPDATE -------
Using Edge and debugging tools and the “Always update from server” setting when downloading from a website ( http://pacmanweb.azurewebsites.net/ ), I see that the game is trying to run before all modules are loaded . If in Chrome it seems that everything loads before the game starts.
Any ideas?
source share