jung34 Posted October 4, 2015 Share Posted October 4, 2015 Hi, Is there a way to tween a rotation between two angles (say -5 to 5 degrees)? I can tween to a single angle and then yoyo; but I'm not sure how to get it to tween between two angles so it rocks back and forth. If possible, I'd prefer to have a single tween rather than two; however if that's the only way, then I'd still be interested to know how to get that to work so that it loops. Link to comment Share on other sites More sharing options...
Rebecca Posted October 4, 2015 Share Posted October 4, 2015 You can use repeat to keep yoyoing. You only need a second tween to get to your start rotation. Link to comment Share on other sites More sharing options...
Tom Atom Posted October 4, 2015 Share Posted October 4, 2015 Hi, you can write your custom easing function: Here is working example: var s = new Phaser.Sprite(this.game, this.world.centerX, this.world.centerY, "Game", "VerticalCannonSprite"); s.anchor.setTo(0.5, 1); this.world.add(s); this.add.tween(s).to({ angle: 45 }, 2000, function(k) { return Math.sin(Math.PI * 2 * k); }, true, 0, -1);Just return some value for input (k) from 0 to 1. The angle value 45 degrees then works like amplitude. I wrote article about custom tweens even with parameters on my blog: http://sbcgamesdev.blogspot.cz/2015/04/phaser-tutorial-custom-easing-functions.htmlIt is also used for enemy drones movement in this simple game tutorial: http://sbcgamesdev.blogspot.cz/2015/05/phaser-tutorial-dronshooter-simple-game.html megmut 1 Link to comment Share on other sites More sharing options...
ForgeableSum Posted October 4, 2015 Share Posted October 4, 2015 function tweenRotation(object) { var randomDelay = rData.between(0, 3000); var amountRotation = 5; object.angle = amountRotation * -1; object.anchor.set(.5); var move = game.add.tween(object).to({ angle: amountRotation, }, 3500, Phaser.Easing.Quadratic.InOut, true, randomDelay, -1, true); }rData is phasers random data generator. Link to comment Share on other sites More sharing options...
jung34 Posted October 4, 2015 Author Share Posted October 4, 2015 Thank you Tom, feudalwars, I learned something from both your posts. I've used Tom's approach as it was the easiest to update my code Have a great day! Link to comment Share on other sites More sharing options...
Recommended Posts