2013-12-17 16:48:03 +00:00
|
|
|
|
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
|
|
var ball;
|
|
|
|
var tilesprite;
|
|
|
|
var cursors;
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
|
|
|
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
|
|
|
game.load.image('ball', 'assets/sprites/pangball.png');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
ball = game.add.sprite(400, 0, 'ball');
|
2014-02-28 18:22:52 +00:00
|
|
|
ball.physicsEnabled = true;
|
2013-12-17 16:48:03 +00:00
|
|
|
|
|
|
|
tilesprite = game.add.tileSprite(300, 450, 200, 100, 'starfield');
|
2014-02-28 18:22:52 +00:00
|
|
|
|
|
|
|
tilesprite.physicsEnabled = true;
|
|
|
|
// tilesprite.body.immovable = true;
|
|
|
|
|
|
|
|
// tilesprite.body.setRectangle(200, 100, 0, 0);
|
2013-12-17 16:48:03 +00:00
|
|
|
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
2014-02-05 05:54:25 +00:00
|
|
|
tilesprite.x -= 8;
|
|
|
|
tilesprite.tilePosition.x -= 8;
|
2013-12-17 16:48:03 +00:00
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
2014-02-05 05:54:25 +00:00
|
|
|
tilesprite.x += 8;
|
|
|
|
tilesprite.tilePosition.x += 8;
|
2013-12-17 16:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
|
|
|
tilesprite.tilePosition.y += 8;
|
|
|
|
}
|
|
|
|
else if (cursors.down.isDown)
|
|
|
|
{
|
|
|
|
tilesprite.tilePosition.y -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
2014-03-03 01:19:31 +00:00
|
|
|
// game.debug.physicsBody(tilesprite);
|
2013-12-17 16:48:03 +00:00
|
|
|
|
|
|
|
}
|