phaser/examples/wip/group fixed to cam.js
photonstorm e5e643b103 fixedToCamera now works across all display objects. When enabled it will fix at its current x/y coordinate, but can be changed via cameraOffset.
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.
2014-02-15 01:27:42 +00:00

68 lines
1.2 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');
}
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');
var group = game.add.group();
for (var i = 0; i < 20; i++)
{
group.create(Math.random() * 800, Math.random() * 600, 'coke');
}
group.fixedToCamera = true;
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() {
}