JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://github.com/photonstorm/phaser/releases/download/v2.6.2/phaser.min.js"></script>
JavaScript
//this game will have only 1 state
var GameState = {
//load the game assets before the game starts
preload: function() {
//adding sprites
this.load.image('ball','assets/images/ball.png');
this.load.image('paddle','assets/images/paddle.png');
},
//executed after everything is loaded
create: function() {
//adding background
game.stage.backgroundColor = '#d3de33';
//adding ball
ball = this.game.add.sprite(game.world.centerX,game.world.centerY,'ball');
ball.scale.setTo(0.1);
//adding paddles
paddleLeft = this.game.add.sprite(5, game.world.centerY, 'paddle');
paddleLeft.anchor.setTo(0.5,0.5);
paddleRight = this.game.add.sprite(795, game.world.centerY, 'paddle');
paddleRight.anchor.setTo(0.5,0.5);
},
update: function() {
//paddle movemment
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
paddleLeft.y -= 1;
} else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
paddleLeft.y += 1;
};
},
render(){
//render paddles
game.debug.spriteInfo(paddleLeft, 20, 32);
}
};
//initiate the Phaser framework
var game = new Phaser.Game(800, 600, Phaser.AUTO);
game.state.add('GameState', GameState);
game.state.start('GameState');