bluedot Posted July 17, 2014 Share Posted July 17, 2014 Hi, I've got 4 objects in a 2x2 grid, I'm using the following code to generate a tween where the object exchange positions with each other:rotateLeft: function() { var tempX = this.diskGroup[0].x; var tempY = this.diskGroup[0].y; this.game.add.tween(this.diskGroup[0]).to( {x: this.diskGroup[2].x, y: this.diskGroup[2].y }, 2400, Phaser.Easing.Linear.None, true); this.game.add.tween(this.diskGroup[2]).to( {x: this.diskGroup[3].x, y: this.diskGroup[3].y }, 2400, Phaser.Easing.Linear.None, true); this.game.add.tween(this.diskGroup[3]).to( {x: this.diskGroup[1].x, y: this.diskGroup[1].y }, 2400, Phaser.Easing.Linear.None, true); this.game.add.tween(this.diskGroup[1]).to( {x: tempX, y: tempY }, 2400, Phaser.Easing.Linear.None, true);},However, each tween puts the objects slightly out of position so eventually the 2x2 grid is compromised. How do I make sure that the objects ends up in the exact position of the target ? Thanks. Link to comment Share on other sites More sharing options...
lewster32 Posted July 17, 2014 Share Posted July 17, 2014 Tweening should not be inaccurate, and should always place objects exactly at the position you tell it to. Tweened properties will always finish on the provided values. I'd check to make sure the x and y positions you're feeding the tweens are correct. The only thing I can think of is that by using the positions of other objects that are also tweening, you may be getting them prematurely before the previous tween has finished. To ensure this doesn't happen I'd provide specific x and y coordinates to each object, rather than rely on the position of another object being exact when you read it. Link to comment Share on other sites More sharing options...
bluedot Posted July 17, 2014 Author Share Posted July 17, 2014 Hi, Thanks for the answer. I had a brainfade moment and forgot to block the input while the tween is in process. So the game was adding tweens while the object were in motions so of course all the x+y were wrong. Thanks again. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts