phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.94k stars 7.08k forks source link

velocityFromAngle moves sprite to wrong place; x/y values "jump" during update #575

Closed kenray closed 10 years ago

kenray commented 10 years ago

In using Phaser 2, I ran into this situation... I have a sprite that slides in from offscreen on the right of the stage to a point partially on the stage. In Phaser 1.1.6, this worked properly, which you can see here: Phaser 1.1.6 Version.

In Phaser 2, the same code (adjusted to call out the Arcade physics engine explicitly) animates the sprite to a different location: Phaser 2 Version.

The source of the page(s) includes the JS, and when I dump the log of the various x/y coordinates, you can see the differences between the two; in 1.1.6 the first few lines of output show a stead progression from start point ("Start") (-167,561) to end ("Target") point (-23,501), showing both the current ("Curr") point (using sprite.x) as well as the current body ("CurrBody") point (using sprite.body.x):

Start: -167,561 / Curr: -167,561 / CurrBody: -271.5,433.5 / Target: -23,501
Start: -167,561 / Curr: -167,561 / CurrBody: -254.29898013052548,426.07509933691745 / Target: -23,501
Start: -167,561 / Curr: -149.79898013052548,553.5750993369174 / CurrBody: -252.23240864755746,425.18302774636027 / Target: -23,501
Start: -167,561 / Curr: -147.73240806519232,552.6830538410902 / CurrBody: -249.0412073482503,423.80554834670426 / Target: -23,501

In 2.0, the first few lines show a jump in both the Curr and CurrBody, resulting in the movements being way off:

Start: -167,561 / Curr: -167,561 / CurrBody: -167,561 / Target: -23,501
Start: -167,561 / Curr: -62.5,688.5 / CurrBody: -164.564235650916,559.948590928453 / Target: -23,501
Start: -167,561 / Curr: -60.064235650916004,687.448590928453 / CurrBody: -70.61332504339052,519.394241025924 / Target: -23,501
Start: -167,561 / Curr: 33.88667495660948,646.894241025924 / CurrBody: -64.00196466730539,516.5404164031534 / Target: -23,501

And adding an additional arnold.anchor.setTo(0.5, 0.5) after physics is enabled didn't help (the values shifted by only a few pixels:

Start: -167,561 / Curr: -167,561 / CurrBody: -167,561 / Target: -23,501
Start: -167,561 / Curr: -62.5,688.5 / CurrBody: -161.08457229508173,558.4465779691001 / Target: -23,501
Start: -167,561 / Curr: -56.58457229508173,685.9465779691001 / CurrBody: -66.4377290163894,517.5918254747005** / Target: -23,501
Start: -167,561 / Curr: 38.0622709836106,645.0918254747005 / CurrBody: -60.870267647054554,515.1886047397359 / Target: -23,501

This looks to me like a legit bug, but I'm pretty new to Phaser, so if I am misunderstanding the new changes, please let me know.

InteractStudios commented 10 years ago

This definitely seems to be a bug. Any idea on when this might get fixed?

photonstorm commented 10 years ago

Please try the latest build in the dev branch. Your test case works as expected now under that release: https://github.com/photonstorm/phaser/tree/dev/build