phaser/TS Tests/cameras/world sprite.js
2013-08-28 07:02:57 +01:00

56 lines
1.7 KiB
JavaScript

/// <reference path="../../Phaser/Game.ts" />
/// <reference path="../../Phaser/utils/DebugUtils.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render);
function preload() {
game.world.setSize(1920, 1200, true);
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
game.load.image('ball', 'assets/sprites/mana_card.png');
}
var ball;
function create() {
game.add.sprite(0, 0, 'backdrop');
ball = game.add.sprite(200, 200, 'ball');
ball.body.velocity.x = 50;
ball.transform.scale.setTo(2, 2);
}
function update() {
/*
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 4;
//ball.x -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 4;
//ball.x += 4;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 4;
//ball.y -= 4;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 4;
//ball.y += 4;
}
*/
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
ball.x -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
ball.x += 4;
}
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
ball.y -= 4;
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
ball.y += 4;
}
}
function render() {
Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 32);
Phaser.DebugUtils.renderSpriteInfo(ball, 32, 200);
}
})();