JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser-ce/2.9.4/phaser.js"></script>
JavaScript
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render:render});
var player;
var cursors;
var jumpButton;
var bulletTime = 0;
function preload() {
game.stage.backgroundColor = '#0aff00';
game.load.baseURL = 'http://examples.phaser.io/assets/';
game.load.crossOrigin = 'anonymous';
game.load.image('player', 'sprites/phaser-dude.png');
game.load.image('platform', 'sprites/platform.png');
game.load.image('bullet', 'games/invaders/enemy-bullet.png');
}
function create() {
player = game.add.sprite(350, 200, 'player');
game.physics.arcade.enable(player);
player.body.collideWorldBounds = true;
cursors = game.input.keyboard.createCursorKeys();
shootButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
player.customParams = {};
bullets = game.add.group();
bullets.enableBody = true;
bullets.physicsBodyType = Phaser.Physics.ARCADE;
bullets.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
// All 40 of them
bullets.createMultiple(40, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 0.5);
bullets.setAll('outOfBoundsKill', true);
bullets.setAll('checkWorldBounds', true);
bullets2 = game.add.group();
bullets2.enableBody = true;
bullets2.physicsBodyType = Phaser.Physics.ARCADE;
bullets2.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
// All 40 of them
bullets2.createMultiple(40, 'bullet');
bullets2.setAll('anchor.x', 0.5);
bullets2.setAll('anchor.y', 0.5);
bullets2.setAll('outOfBoundsKill', true);
bullets2.setAll('checkWorldBounds', true);
}
function update () {
game.physics.arcade.collide(player);
player.body.velocity.x = 0;
if (cursors.left.isDown || player.customParams.isMovingLeft)
{
player.body.velocity.x = -250;
}
if (cursors.right.isDown ||...