# Group rotation

## 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)?

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

##### Share on other sites

So your advice is to move each sprite from the group and rotate it? or then rotate group? will it cause any visual defects? because I need to do this on moving element (tweening).. or maybe I just didn't understand?

##### 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`

##### Share on other sites

I would suggest you rotate the group itself, if that is the effect you require (hard to know without more info).

##### Share on other sites

Thanks Rotation is working fine now

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.