swemaniac Posted November 4, 2014 Share Posted November 4, 2014 Hi, First off thanks to Phaser. It's awesome. How do I tween a sprite's angle from say 180 degrees to 360 degrees in a clockwise direction? If i just do tween.to({ angle: 360}) the sprite will rotate counter clockwise. In Phaser angles that would be from 180 to -90. Obviously it's because the tween will go down from 180 to -90, but I want it to to go upwards and wrap around i.e. 180, -179, -178 etc. Make any sense? Thanks Link to comment Share on other sites More sharing options...
lewster32 Posted November 5, 2014 Share Posted November 5, 2014 Tweens usually aren't very smart about how they work - essentially all a tweener does is gradually change one number to another, so angles are often problematic. You'd be better off adding something to your update function which increments the sprite.angle by a small amount each frame:function update() { if (sprite.isRotating) { sprite.angle += 1; }}Then all you have to do is set sprite.isRotating to true and it'll start turning steadily. Be aware that this is a naive implementation that doesn't account for framerate differences; it'll turn slower with lower framerates. There are easy ways to tackle that if needs be. Link to comment Share on other sites More sharing options...
swemaniac Posted November 5, 2014 Author Share Posted November 5, 2014 Ok thanks lewster. Yeah the concept of tweens seems very attractive at first but they don't really fit when you need to do more advanced stuff I noticed. Link to comment Share on other sites More sharing options...
lewster32 Posted November 6, 2014 Share Posted November 6, 2014 If you want advanced tweens which work well with rotation, check out GSAP. It plays well with Phaser, and I tend to use it for larger projects where I need fine control over tweens. Link to comment Share on other sites More sharing options...
Recommended Posts