Closed ritzbitz01 closed 10 years ago
Just tested the following in 2.0.6-dev and nothing flies off anywhere:
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
}
var sprite;
function create() {
game.world.setBounds(0, 0, 1600, 600);
sprite = game.make.sprite(100, 0, 'atari');
game.camera.x = 100;
game.add.existing(sprite);
}
function update() {
}
function render() {
}
Here's a version with physics enabled on the sprite too, still doesn't fly off. Going to close this, but feel free to re-open with a test case.
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari', 'assets/sprites/atari130xe.png');
}
var sprite;
function create() {
game.world.setBounds(0, 0, 1600, 1200);
game.physics.startSystem(Phaser.Physics.ARCADE);
sprite = game.make.sprite(500, 200, 'atari');
game.physics.arcade.enable(sprite);
game.camera.x = 100;
game.add.existing(sprite);
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
if (cursors.up.isDown)
{
game.camera.y -= 4;
}
else if (cursors.down.isDown)
{
game.camera.y += 4;
}
if (cursors.left.isDown)
{
game.camera.x -= 4;
}
else if (cursors.right.isDown)
{
game.camera.x += 4;
}
}
function render() {
}
Using phaser 2.0.5 stable. After moving the camera (ex. game.camera.y += 4), then calling game.add.existing(sprite), the sprite added to the game has the number of pixels the camera moved added to its respective x or y value on every game update.
Please see the following forum topic about this issue:
http://www.html5gamedevs.com/topic/7302-gameaddexisting-issue-after-moving-camera/
This action does not occur in 2.0.4, so must have been introduced in 2.0.5, the version I downloaded.