Madigan Posted October 12, 2013 Share Posted October 12, 2013 Hey folks! I'm trying to make a game of Asteroids, and I want to steer my ship! So I added the following code to change the angle:if(game.input.keyboard.isDown(Phaser.Keyboard.D)) player.angle++;It works at first, but then it gets stuck and the angle won't change. Generally this happens after 360* or so. I'm guessing that this has something to do with the number getting too large (which mathematically shouldn't make a difference, right?). I created a workaround:var rotation = 0;function update() { if(game.input.keyboard.isDown(Phaser.Keyboard.D)) player.angle = rotation++ % 360;}But creating my own rotation variable seems to defeat the purpose of having an angle variable in the first place. Am I doing something wrong? Is there a better way to make use of angle? I've been looking through the source, but I haven't had much luck yet (JavaScript is not my first language). Thanks & Regards. Link to comment Share on other sites More sharing options...
rich Posted October 12, 2013 Share Posted October 12, 2013 Actually I fixed this in 1.0.7-dev, so I'd suggest moving to that please Also there's a good example in the new physics set of how to use angular acceleration too. Link to comment Share on other sites More sharing options...
Madigan Posted October 12, 2013 Author Share Posted October 12, 2013 Awesome! Will do. Thanks. Link to comment Share on other sites More sharing options...
rich Posted October 12, 2013 Share Posted October 12, 2013 Also just to explain: sprite.rotation - this value is in radians and is unboundsprite.angle - this value is in degrees (-+ 180) and is wrapped from ever going too high/low Link to comment Share on other sites More sharing options...
Madigan Posted October 13, 2013 Author Share Posted October 13, 2013 It looks like I spoke too soon... I'm still getting the same problem. I grabbed 1.0.7, and I looked at the changes, but I'm having the same problem. I'll hold down the "D" key, and it'll get stuck at some random angle. I was wondering if my input code was causing any problems, so I simplified it to:function update() { player.angle++;}It gets up to 2.3038346126325204 rads or 132.0000000000003 degrees, then freezes. For the life of me I can't figure out why. Could there be some floating-point magick going on? Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 Actually it's weirder than that - check this out:player.angle++;// fails for me when it hits 132 degplayer.angle += 1;// works perfectly! Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 There must be something about how the getters/setters are working causing this. I've no idea what it is though, will have to investigate further! Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 Even stranger - it only happens in Chrome. In Firefox or IE it works perfectly using angle++ I've tried renaming angle, using a temporary var, all sorts - but Chrome locks up after 132 modifications (regardless of ++ or --). Definitely a Chrome bug. Time to submit Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 Here we go: https://code.google.com/p/chromium/issues/detail?id=306851 Star it to get them to fix it sooner Mike 1 Link to comment Share on other sites More sharing options...
gaelbeltran Posted October 13, 2013 Share Posted October 13, 2013 Definitely needs to be fixed. Starred. Link to comment Share on other sites More sharing options...
Recommended Posts