سؤال

I have a group of sprites in a node;

E.g.

CCNode *grid = [CCNode node];
CCSprite *sprite1 = [CCSprite spriteWithImageNamed:@"sprite.png"];
[grid addChild:sprite1];
CCSprite *sprite2 = [CCSprite spriteWithImageNamed:@"sprite.png"];
[grid addChild:sprite2];
CCSprite *sprite3 = [CCSprite spriteWithImageNamed:@"sprite.png"];
[grid addChild:sprite3];

Anyway, the end result ends up being a 5x5 grid of tiles. I plan on rotating all the tiles 90 degrees together. My current code for that is this:

[grid runAction:[CCActionRotateBy actionWithDuration:1 angle:90]];

Now, the problem is that the group of sprites aren't just rotating, the whole group is "orbiting" around a point (looks like the bottom left of the group of sprites) and goes off the screen and I only want it to rotate the group of sprites while they remaining stationary.

I have tried setting the anchor to (0,0), (.5, .5), (1, 1), etc... but, that doesn't change anything.

For those who are more visual

All help greatly appreciated.

هل كانت مفيدة؟

المحلول 2

Finally with a lot of trial and error, I have found the solution.

When I made the new node and was adding sprites to it, the content size of the node stayed the same. I had to provide the length of the entire grid as the content size and then adjust the position and now the anchor point is the center of the grid.

نصائح أخرى

You are rotating the grid. If you want each tile to rotate individually you need to run one rotate action on each grid sprite, but not rotate the grid.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top