mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
e5e643b103
fixedToCamrea now works for Groups as well :) You can fix a Group to the camera and it will influence its children. Also fixed the issue with World.preUpdate/postUpdate not being called and various small documentation issues.
83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
function preload() {
|
|
|
|
game.load.image('backdrop', 'assets/pics/remember-me.jpg');
|
|
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
|
game.load.image('coke', 'assets/sprites/cokecan.png');
|
|
game.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml', null, 0, -32);
|
|
|
|
}
|
|
|
|
var cursors;
|
|
var mushroom;
|
|
|
|
function create() {
|
|
|
|
game.world.setBounds(0, 0, 1920, 1200);
|
|
game.add.image(0, 0, 'backdrop');
|
|
|
|
mushroom = game.add.sprite(400, 400, 'mushroom');
|
|
|
|
// Test Fixing an Image to the Camera
|
|
var fixie = game.add.image(100, 100, 'coke');
|
|
fixie.fixedToCamera = true;
|
|
|
|
// And tween it
|
|
game.add.tween(fixie.cameraOffset).to({ y: 500 }, 2000, Phaser.Easing.Bounce.Out, true, 0, 1000, true);
|
|
|
|
// Test Fixing a Sprite to the Camera
|
|
var fixie2 = game.add.sprite(600, 100, 'coke');
|
|
fixie2.fixedToCamera = true;
|
|
fixie2.inputEnabled = true;
|
|
fixie2.events.onInputDown.add(clicked, this);
|
|
|
|
// Test Fixing a Text to the Camera
|
|
var text = game.add.text(300, 32, '-phaser-');
|
|
text.fixedToCamera = true;
|
|
|
|
// Test fixing a BitmapText to the Camera
|
|
var text2 = game.add.bitmapText(200, 500, 'desyrel', 'camera fixies', 32);
|
|
text2.fixedToCamera = true;
|
|
|
|
// Button! do mouse events still work then?
|
|
|
|
game.camera.follow(mushroom);
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
|
|
|
}
|
|
|
|
function clicked() {
|
|
|
|
console.log('boom');
|
|
|
|
}
|
|
|
|
function update() {
|
|
|
|
if (cursors.left.isDown)
|
|
{
|
|
mushroom.x -= 8;
|
|
}
|
|
else if (cursors.right.isDown)
|
|
{
|
|
mushroom.x += 8;
|
|
}
|
|
|
|
if (cursors.up.isDown)
|
|
{
|
|
mushroom.y -= 8;
|
|
}
|
|
else if (cursors.down.isDown)
|
|
{
|
|
mushroom.y += 8;
|
|
}
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
|
|
}
|