rea Posted November 20, 2013 Share Posted November 20, 2013 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 More sharing options...
rich Posted November 21, 2013 Share Posted November 21, 2013 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 More sharing options...
rea Posted November 21, 2013 Author Share Posted November 21, 2013 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? Link to comment Share on other sites More sharing options...
hackenstein Posted November 21, 2013 Share Posted November 21, 2013 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 More sharing options...
rich Posted November 21, 2013 Share Posted November 21, 2013 I would suggest you rotate the group itself, if that is the effect you require (hard to know without more info). Link to comment Share on other sites More sharing options...
rea Posted November 21, 2013 Author Share Posted November 21, 2013 Thanks Rotation is working fine now Link to comment Share on other sites More sharing options...
Recommended Posts