xronn Posted September 2, 2014 Share Posted September 2, 2014 Hi,My sprites direction of travel is controlled by the angle in which he is facing so he basically only gos up but the angle makes him move left and right. if (this.cursor.left) { this.tank.angle = 180; this.currentSpeed = 80; this.tank.animations.play('left', 7, true); } else if (this.cursor.right) { this.tank.angle = 360; this.currentSpeed = 80; this.tank.animations.play('right', 7, true); } if (this.cursor.up) { this.tank.angle = 270; this.currentSpeed = 80; this.tank.animations.play('up', 7, true); } else { if (this.currentSpeed > 0) { this.currentSpeed -= 1; } else { this.tank.animations.play('standing', 7, true); } } if (this.currentSpeed > 0) { game.physics.arcade.velocityFromRotation(this.tank.rotation, this.currentSpeed, this.tank.body.velocity); } else { game.physics.arcade.velocityFromRotation(this.tank.rotation, 0, this.tank.body.velocity); }The only problem is the sprites orientation changes based on the angle, of course it would you've just told it to..Without having to flip my hard assets so they appear to be facing the right way (not upside down) I was wondering if phaser had a similar function to the immovable but for rotation!Thanks! Link to comment Share on other sites More sharing options...
eguneys Posted September 2, 2014 Share Posted September 2, 2014 I don't understand the problem can you describe it in some other way. Link to comment Share on other sites More sharing options...
xronn Posted September 2, 2014 Author Share Posted September 2, 2014 So to move my sprite left and right force the angle of the sprite to change e.gthis.tank.angle = 360;Setting the player sprite at 360 degrees, when you press this key it now moves to the right as that's the way the sprite is facing.but forcing an angle on the sprite also rotates the image as your setting it at an angle, I want to angle in the sprite in order to move it but not actually rotate the sprite. Link to comment Share on other sites More sharing options...
eguneys Posted September 3, 2014 Share Posted September 3, 2014 You want to move a sprite to any direction, and you are using angle to achieve that. But angle causes sprite to rotate and you don't want that. Well don't use angle because that is for actually rotating the sprite. There are many other alternative methods to move a sprite to any direction. http://docs.phaser.io/Phaser.Physics.Arcade.html#accelerateToXYhttp://docs.phaser.io/Phaser.Physics.Arcade.html#moveToXY But actually to solve your problem you can still use velocityFromRotation like this:// remove this, don't set angle on the sprite// this.tank.angle = 360;// Use any angle you want, just don't use sprite's rotationvar anyAngle = 270;game.physics.arcade.velocityFromAngle(anyAngle, this.currentSpeed, this.tank.body.velocity);Note that there are two similar methods:velocityFromRotation, is passed angle in radian, as in PI.velocityFromAngle, is passed angle in degrees, as in 360. So you should use the velocityFromAngle for degrees. Link to comment Share on other sites More sharing options...
Recommended Posts