javaandroidcocos2d-androidanchorpointccrotateby

RotateBy Anchorpoint not affecting rotation


In Cocos2d (Android, JAVA), I use CCRotateBy to rotate one CCNode with several tiles in it as children. I want to use the center of the center tile as a point of rotation, so I thought I'd use Anchorpoint.

However, it doesn't matter what value I give to the Anchorpoint, tiles keep rotating around the bottom left of my screen. How come?

(the tiles are CCNodes, collected in two lists, tilesSelected and secondaryTilesSelected)

            // I create one node which holds all the tiles I want to rotate
            CCNode tilesToRotate = CCNode.node();

            tilesToRotate.addChild(tilesSelected.get(0), 0, 99);
// then, I add the 4 tiles around the previous, center tile

            for (int i=0; i < secondaryTilesSelected.size(); i++){

                tilesToRotate.addChild(secondaryTilesSelected.get(i), 0, 99);
            }
            // So, if I change 700,700 hereunder to different values, it doesn't change the centerpoint for Rotation. I guess I don't get it...

            addChild(tilesToRotate);
            tilesToRotate.setAnchorPoint(CGPoint.make(700,700));
            CCAction r90 = CCRotateBy.action(1f, 90f);
            tilesToRotate.runAction(r90);

Solution

  • anchorPoint is a factor in the range 0,0 (lower left corner) to 1,1 (upper right corner of content)

    You are setting the anchor far too far away from the node at 700,700