mirror of
https://github.com/wassname/phaser.git
synced 2026-08-11 11:23:06 +08:00
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.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '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('starfield', 'assets/misc/starfield.jpg');
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
var cursors;
|
||||
var mushroom;
|
||||
|
||||
function create() {
|
||||
|
||||
game.world.setBounds(0, 0, 1920, 1200);
|
||||
game.add.image(0, 0, 'backdrop');
|
||||
|
||||
sprite = game.add.tileSprite(100, 100, 200, 200, 'starfield');
|
||||
sprite.autoScroll(0, 100);
|
||||
sprite.fixedToCamera = true;
|
||||
|
||||
mushroom = game.add.sprite(400, 400, 'mushroom');
|
||||
|
||||
game.camera.follow(mushroom);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
// game.debug.renderText(sprite.frame, 32, 32);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user