phaser/Tests/cameras/camera scale.js

46 lines
1.9 KiB
JavaScript
Raw Normal View History

2013-04-18 13:16:18 +00:00
/// <reference path="../../Phaser/Phaser.ts" />
2013-04-12 16:19:56 +00:00
(function () {
2013-04-18 13:16:18 +00:00
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
2013-04-12 16:19:56 +00:00
function init() {
myGame.world.setSize(2240, 2240);
myGame.loader.addImageFile('grid', 'assets/tests/debug-grid-1920x1920.png');
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
myGame.loader.load();
}
var car;
var miniCam;
var bigCam;
function create() {
myGame.createSprite(0, 0, 'grid');
car = myGame.createSprite(400, 300, 'car');
myGame.camera.follow(car);
2013-04-18 13:16:18 +00:00
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
2013-04-12 16:19:56 +00:00
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
miniCam = myGame.createCamera(600, 32, 200, 200);
2013-04-18 13:16:18 +00:00
miniCam.follow(car, Phaser.Camera.STYLE_LOCKON);
2013-04-12 16:19:56 +00:00
miniCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
miniCam.showBorder = true;
miniCam.scale.setTo(0.5, 0.5);
bigCam = myGame.createCamera(32, 32, 200, 200);
2013-04-18 13:16:18 +00:00
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
2013-04-12 16:19:56 +00:00
bigCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
bigCam.showBorder = true;
bigCam.scale.setTo(2, 2);
}
function update() {
car.velocity.x = 0;
car.velocity.y = 0;
car.angularVelocity = 0;
car.angularAcceleration = 0;
2013-04-18 13:16:18 +00:00
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
2013-04-12 16:19:56 +00:00
car.angularVelocity = -200;
2013-04-18 13:16:18 +00:00
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
2013-04-12 16:19:56 +00:00
car.angularVelocity = 200;
}
2013-04-18 13:16:18 +00:00
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
2013-04-12 16:19:56 +00:00
car.velocity.copyFrom(motion);
}
}
})();