JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://rawgit.com/photonstorm/phaser/dev/build/phaser.js"></script>
<div id ="phaser"></div>
JavaScript
var game = new Phaser.Game(400, 400, Phaser.CANVAS, 'phaser', { create: create, update: update});
var ufo;
var Keys = Phaser.Keyboard;
var speed = 40;
var style = 'default';
function create() {
// Make the world larger than the actual canvas
game.world.setBounds(0, 0, 14000, 14000);
ufo = game.add.sprite(300, 240, 'test');
game.physics.startSystem(Phaser.Physics.ARCADE);
game.physics.enable(ufo, Phaser.Physics.ARCADE);
//registration point
ufo.anchor.setTo(0.5, 0.5);
game.camera.follow(ufo);
}
function update() {
if (game.input.keyboard.isDown(Keys.LEFT))
{
ufo.body.velocity.x = -speed;
ufo.angle = -15;
}
else if (game.input.keyboard.isDown(Keys.RIGHT))
{
ufo.body.velocity.x = speed;
ufo.angle = 15;
}
else
{
ufo.angle = 0;
ufo.body.velocity.set(0,0);
}
}