Jump to content

Placing Sprites relative to groups


Recommended Posts

I am trying to create a board that spins 

if I add everything to worldGroup this works 

create: function () {
    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));

  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));

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


  • Recently Browsing   0 members

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