var config = { type: Phaser.AUTO, parent: 'phaser-example', backgroundColor: '#0072bc', physics: { default: 'arcade', arcade: { debug: true } }, scene: { preload: preload, create: create, update: update } }; var cursors; var player; var game = new Phaser.Game(config); function preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v355'); this.load.image('block', 'assets/sprites/block.png'); } function create () { cursors = this.input.keyboard.createCursorKeys(); player = this.physics.add.image(400, 300, 'block'); player.setCollideWorldBounds(true); } function update () { player.setVelocity(0); if (cursors.left.isDown) { player.setVelocityX(-300); } else if (cursors.right.isDown) { player.setVelocityX(300); } if (cursors.up.isDown) { player.setVelocityY(-300); } else if (cursors.down.isDown) { player.setVelocityY(300); } }
Scan to open on your mobile device
var config = { type: Phaser.AUTO, parent: 'phaser-example', backgroundColor: '#0072bc', physics: { default: 'arcade', arcade: { debug: true } }, scene: { preload: preload, create: create, update: update } }; var cursors; var player; var game = new Phaser.Game(config); function preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v355'); this.load.image('block', 'assets/sprites/block.png'); } function create () { cursors = this.input.keyboard.createCursorKeys(); player = this.physics.add.image(400, 300, 'block'); player.setCollideWorldBounds(true); } function update () { player.setVelocity(0); if (cursors.left.isDown) { player.setVelocityX(-300); } else if (cursors.right.isDown) { player.setVelocityX(300); } if (cursors.up.isDown) { player.setVelocityY(-300); } else if (cursors.down.isDown) { player.setVelocityY(300); } }