phaser/Tests/cameras/focus on.js

37 lines
1.5 KiB
JavaScript
Raw Normal View History

/// <reference path="../../Phaser/Game.ts" />
2013-04-12 17:19:56 +01:00
(function () {
2013-04-18 14:16:18 +01:00
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
2013-04-12 17:19:56 +01:00
function init() {
myGame.world.setSize(1920, 1920);
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
myGame.loader.addImageFile('melon', 'assets/sprites/melon.png');
myGame.loader.addImageFile('carrot', 'assets/sprites/carrot.png');
myGame.loader.load();
}
var melon;
function create() {
// locked to the camera
myGame.createSprite(0, 0, 'grid');
melon = myGame.createSprite(600, 650, 'melon');
melon.scrollFactor.setTo(1.5, 1.5);
// scrolls x2 camera speed
for(var i = 0; i < 100; i++) {
var tempSprite = myGame.createSprite(Math.random() * myGame.world.width, Math.random() * myGame.world.height, 'carrot');
tempSprite.scrollFactor.setTo(2, 2);
}
}
function update() {
myGame.camera.renderDebugInfo(32, 32);
melon.renderDebugInfo(200, 32);
2013-04-18 14:16:18 +01:00
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
2013-04-12 17:19:56 +01:00
myGame.camera.focusOnXY(640, 640);
2013-04-18 14:16:18 +01:00
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
2013-04-12 17:19:56 +01:00
myGame.camera.focusOnXY(1234, 800);
2013-04-18 14:16:18 +01:00
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
2013-04-12 17:19:56 +01:00
myGame.camera.focusOnXY(50, 200);
2013-04-18 14:16:18 +01:00
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
2013-04-12 17:19:56 +01:00
myGame.camera.focusOnXY(1700, 1700);
}
}
})();