nazimboudeffa Posted November 9, 2016 Share Posted November 9, 2016 i want to turn a sprite with keyboard hotkey every time i tape SPACEBAR, how is it possible the game is here http://asciimulation.link/codeinmass/mod/ and, this is a continuation of this thread turn90: function(){ var a = Math.floor(this.player.x / gameOptions.tileSize); var b = Math.floor(this.player.y / gameOptions.tileSize); console.log(a, b); game.add.tween(this.tilesArray[b][a]).to( { angle: 90 }, 200, Phaser.Easing.Linear.None, true); } Link to comment Share on other sites More sharing options...
s4m_ur4i Posted November 10, 2016 Share Posted November 10, 2016 Turn in direction or just flip the graphic? I won't use a tween to do this. If you want to animate it, it would be "a good way" to make some graphics, an animation and do an "animation.onComplete.add()" inside the following examples: you could make a method for flip the graphic: flipSprite () { this.scale.x >= 0 ? this.scale.x = -1 : this.scale = 1; } for turn the direction, I use a method like this: MySprite { constructor() { ..some code.. game.physics.arcade.enable(this); this.body.allowGravity = true; this.body.allowRotation = false; this.data.speed = 70; this.data.direction = 'right'; this.body.velocity.x = this.data.speed; } turnSprite() { this.body.velocity.x = this.body.velocity.x > 0 ? this.body.velocity.x = -this.data.speed : this.data.speed; } } I hope that helps, regards Link to comment Share on other sites More sharing options...
nazimboudeffa Posted November 13, 2016 Author Share Posted November 13, 2016 thank you for you response, i don't understand all the code but another way seems interesting to explore then a tween animation but i just want the tile to rotate at 90° at this moment it works only one time Link to comment Share on other sites More sharing options...
ForgeableSum Posted November 13, 2016 Share Posted November 13, 2016 3 minutes ago, thefailtheory said: thank you for you response, i don't understand all the code but another way seems interesting to explore then a tween animation but i just want the tile to rotate at 90° at this moment it works only one time tile.angle += 90. Link to comment Share on other sites More sharing options...
nazimboudeffa Posted November 13, 2016 Author Share Posted November 13, 2016 i just have tryed it it doesnt work so here is the code theclickroller.zip Link to comment Share on other sites More sharing options...
ForgeableSum Posted November 13, 2016 Share Posted November 13, 2016 Worked for me. The only problem I saw is that you can only change the angle on the tile once (because it will always go to 90). I think this is your intention: var newAngle = this.tilesArray[b][a].angle + 90; turnTween = game.add.tween(this.tilesArray[b][a]).to( { angle: newAngle }, 200, Phaser.Easing.Linear.None); if (!turnTween.isRunning) { turnTween.start(); } That way you can change the angle on the tile underneath the circle as many times as you want. Link to comment Share on other sites More sharing options...
nazimboudeffa Posted November 13, 2016 Author Share Posted November 13, 2016 yes it is so it means you have to evaluate the tile angle every time and add it 90° i didn't dig on the other solution but yours seems to work now it must work with just 90° because sometimes it turns 45° so next is to find a how to complete the tween until 90° then start at that point Link to comment Share on other sites More sharing options...
Recommended Posts