temporalix Posted March 7, 2014 Share Posted March 7, 2014 Hello. I've been trying to setup some way to tween my sprite to 3 set areas on the screen, but it ends up going from 1 side to the other. left = game.input.keyboard.addKey(Phaser.Keyboard.LEFT); left.onDown.add(function () { pos > -2 ? pos-- : pos; if (pos == 1) { game.add.tween(ufo).to({ x: 400 }, 1000, Phaser.Easing.Linear.None, true, 0); } else { game.add.tween(ufo).to({ x: 250 }, 1000, Phaser.Easing.Linear.None, true, 0); } }, this);right = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); right.onUp.add(function () { pos<2?pos++:pos; if(pos==-1) { game.add.tween(ufo).to({ x: 400 }, 1000, Phaser.Easing.Linear.None, true, 0); } else { game.add.tween(ufo).to({ x: 950 }, 1000, Phaser.Easing.Linear.None, true, 0); } }, this); what am I doing wrong? Link to comment Share on other sites More sharing options...
Arlefreak Posted March 7, 2014 Share Posted March 7, 2014 I think I had exactly the same problem today, try using your sprite x:game.add.tween(ufo).to({ x: ufo.x + 950 }, 1000, Phaser.Easing.Linear.None, true, 0); Link to comment Share on other sites More sharing options...
temporalix Posted March 8, 2014 Author Share Posted March 8, 2014 I got it working after messing around with it a bit , and seeing that the logic inside the button press loops was interfering with the tweens. I ended up moving all the logic into a seperate function which I think makes is cleaner . code:function getPos(dir) { if (dir == 0) { if (moveX > 100) moveX = moveX - 500; spinSpeed = spinSpeed -5; } else { if (moveX < 1000) moveX = moveX + 500; spinSpeed = spinSpeed + 5; } } left = game.input.keyboard.addKey(Phaser.Keyboard.LEFT); left.onDown.add(function () { getPos(0) }, this); left.onUp.add(function () { leftTween = game.add.tween(ufo).to({ x: moveX }, 1000).start(); }, this); right = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); right.onDown.add(function () { getPos(1); }, this); right.onUp.add(function () { rightTween = game.add.tween(ufo).to({ x: moveX }, 1000).start(); }, this); Link to comment Share on other sites More sharing options...
Recommended Posts