Sign in to follow this  
MTiger

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.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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.