Jump to content

Beware of evil newbie trap when moving sprites!


Recommended Posts



I just spent a couple of hours figuring this out:

var t;function moveSpriteUp (dt){  t + = dt;  mySprite.y = 100 + t  * 10;}

That made the sprite rotate, not move. Why? Because t isn't initialized, t + dt is NaN, and setting sprite.x or sprite.y to NaN appearently messes with references so that some other sprite's rotation affects this sprite. I guess all kinds of strange behaivious could occur.


This is how it shoud be:

var t = 0; 

Piously using JSHint didn't help at all...

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...