wombat Posted January 29, 2014 Share Posted January 29, 2014 Hi, 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 More sharing options...
jerome Posted January 29, 2014 Share Posted January 29, 2014 I didn't know about this bug (if it is so).It's a good practice to initialize your variables if you already know their datatype as it helps the js compiler to optimize the generated bytecode. Link to comment Share on other sites More sharing options...
Recommended Posts