I’m really struggling to understand cocos2d 2.0 and how its layers and coordinates work. I have a single scene with a single layer that contains a single sprite. Here are the stats:
Layer: Position: (0,0)
Origin: (-384, -430)
Size: (768, 860) (same as the view)
AnchorPoint: (0.5, 0.5)
ignoreAnchorPointForPosition: NO
Scale: 1.0
Sprite: Position: (768, 860)
Origin: (499.5, 413.5)
Size: (537, 893)
AnchorPoint: (0.5, 0.5)
I add the sprite in the init of the layer.
How is it that the sprite is positioned at the center of the view in the iPad simulator? If someone could help me draw a mental picture (or an actual one :)) of this, that would really help.
This image shows how I understand the placement and it doesn’t make any sense. If this is a bad question or not the correct forum, please let me know and I’ll move it to the correct place.
Anchor point is relative point on the node. (0.f, 0.f) corresponds to left-bottom corner and (1.f, 1.f) is for right-top corner. The position, that you set to the node, is set for anchor point. Of course, if it’s property
isRelatieveAnchorPointisYES.So, if anchor point is (0.5f, 0.5f), you set the position of center of the node. Thats why your layer is placed in (0.f, 0.f) of world coordinates with it’s center.
But inner coordinates are always count from (0.f, 0.f) of current node. So, if you add your sprite to (768.f, 860.f) with sprite’s anchor point (0.5, 0.5f), sprite’s center will be positioned to this coordinates relatieve to the parent layer’s origin.
I hope i described it clear enough =)