Jump to content

Placing Sprites relative to groups


MTiger
 Share

Recommended Posts

I am trying to create a board that spins 

if I add everything to worldGroup this works 

create: function () {
    this.game.world.setBounds(0,0,1200,1200);
...
    this.worldgroup = this.add.group();
    this.worldgroup.pivot.x = this.game.world.centerX;
    this.worldgroup.pivot.y = this.game.world.centerY;
    this.worldgroup.x = this.worldgroup.pivot.x;
    this.worldgroup.y = this.worldgroup.pivot.y;
...
}
rotateRoom: function() {
    ...
    this.worldgroup.rotation += Math.PI/2;
    ...
  },
 


 What I do not understand is this line, my understanding of the documents is that group.create places the sprite x, y, relative to the group so I would expect the sprite to be at 600, 600 but it is placed at 0, 0 in the world
 

 addRoom: function() {
    let tile = this.worldgroup.create(0,0, 'rooms',this.game.rnd.integerInRange(0,9));
    tile.anchor.setTo(0.5);
    
  },
  


  even if I create the sprite then add it to the group like 
  

    let tile = new Phaser.Sprite(this.game, 0,0, 'rooms',this.game.rnd.integerInRange(0,9));
    this.worldgroup.add(tile);
    


What is weird is that if I move worldgroup x/y after the fact the sprite moves relative, like 
 

   this.worldGroup.x +=300


    
What am I missing, how can I place my sprites relative to the center of the world without always adding and subtracting world.centerX, centerY

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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