Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Group rotation


rea
 Share

Recommended Posts

Hi,

 

I started to create a simple game - tetris. Unfortunately I have 2 problems:

 

- how to move group rotation point from top left corner to the center?

- is there a possibility to check collision when moving group by change x property (I override tween, but it still moves down)?

Link to comment
Share on other sites

Think of Groups as being single points in space, centered around their x/y coordinate. Now think of the children as being placed relative to that x/y point. So if you need to place a sprite in the "center" of a group, you need to place the middle of the sprite at 0,0 within the Group. So if you had a sprite that was 100x100 in size you would position it at -50,-50 within the Group. Then if you rotate the group itself it will appear to rotate around its center.

Link to comment
Share on other sites

I think what he meant was: The group actually rotates around its x/y coordinates, but your sprites are probably themselves not placed in the center of the group. To create a sprite in the center of a group you have to subtract it's width/2 from the x and it's height/2 from the y coordinate or set it's anchor to 0.5/0.5.

 

I have not tested it, but this should look like this:

group = game.add.group(10, 10, 'myGroup'); // Create group placed on 10/10 in the world.sprite = group.create(0,0, 'mySpriteSheet'); // Add sprite placed at 0/0 of the group, which is the center.sprite.anchor.setTo(0.5,0.5); // Set anchor to the middle of the sprite
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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