0penS0urce Posted June 18, 2015 Report Share Posted June 18, 2015 I need a code snippet to allow a sprite to orbit the center of the screen, and the direction has to be controlled with the arrow keys, and it has to rotate to face the middle. The code I have right now flips the sprite to the other side of the circle. Thanks in Advance!var game = new Phaser.Game(640, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() { game.load.image('player', 'assets/player.png');}function create() { game.physics.startSystem(Phaser.Physics.ARCADE); x = game.add.sprite(0, 0, 'player'); game.physics.enable(x, Phaser.Physics.ARCADE); x.anchor.setTo(0.5, 0.5); cursors = game.input.keyboard.createCursorKeys();}function update() { var period = game.time.now * 0.001; var radius = 200; if (cursors.left.isDown) { x.x = game.world.centerX - Math.cos(period) * radius; x.y = game.world.centerY - Math.sin(period) * radius; x.angle += 1; } if (cursors.right.isDown) { x.x = game.world.centerX + Math.sin(period) * radius; x.y = game.world.centerY + Math.cos(period) * radius; x.angle -= 1; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.