Jump to content

Are groups fixed to camera?


hackenstein
 Share

Recommended Posts

I'm currently trying to switch to phaser 1.1.2 from 1.0.6a, but I have run into a problem: We use groups to layer the sprites, but now all sprites in groups behave as if they were fixed to the camera. I couldn't find out why this happens, nor if this is how it is supposed to be. But I really need a way to circumvent this behaviour, without loosing the groups :wacko:

 

This behaviour can be easily reproduced in the starstruck example by adding a sprite within a group. Now if you move the camera by walking to the right of the screen, the sprite in the group will stay on screen fixed to the camera.

 

Here is what I added to the starstruck example create function:

function create() {    game.stage.backgroundColor = '#000000';    bg = game.add.tileSprite(0, 0, 800, 600, 'background');    bg.fixedToCamera = true;    map = game.add.tilemap('level1');    tileset = game.add.tileset('tiles');    tileset.setCollisionRange(0, tileset.total - 1, true, true, true, true);    tileset.setCollisionRange(12, 16, false, false, false, false);    tileset.setCollisionRange(46, 50, false, false, false, false);    layer = game.add.tilemapLayer(0, 0, 800, 600, tileset, map, 0);    layer.resizeWorld();    // ADDING SPRITE IN GROUP    group = game.add.group(null, 'test');    dude2 = game.add.sprite(32, 32, 'dude');    group.add(dude2);	    player = game.add.sprite(32, 32, 'dude');       player.body.bounce.y = 0.2;    player.body.collideWorldBounds = true;    player.body.gravity.y = 6;    player.body.setSize(16, 32, 8, 16);    player.animations.add('left', [0, 1, 2, 3], 10, true);    player.animations.add('turn', [4], 20, true);    player.animations.add('right', [5, 6, 7, 8], 10, true);    game.camera.follow(player);    cursors = game.input.keyboard.createCursorKeys();    jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);}
Link to comment
Share on other sites

Sprites in Groups are not fixed to the camera.

 

What has happened is that you created a Group with "null" as the parent. This basically creates it ABOVE the World layer. You use that for like game UI or something fixed. If you need to add a Group within the world then instead of null give it 'game.world' as the parent. Or don't specify any parameters at all, that will do the same thing.

 

I guess what I could do is extend the Group check, so if parent is undefined OR null, it reverts to using the world as the parent.

Link to comment
Share on other sites

Ahh ok, thanks!

Now I just have to find a way to draw the tilemap in the background, because tilemaps & tilelayers can't be in groups anymore. We have placed everything else in groups, that are created at the beginning, so the layering stays consistent through map change etc.

 

EDIT: Turns out you can add tilemap layers to groups! :D

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...