Bek
Bek

Reputation: 31

super init Sprites doesn't match position

a real quick question here. It seems like super init has it's own way anchoring things around. Here is the example. Below i have super init with sprite frame "image1", and i have "image2" within the init. The problem is, these 2 images will not over-lapse each other as you would thought, it appears that the anchor point of init 'image1' is 0,0 and 0.5,0.5 for "image2" so the lower left edge of "image1" would be over-lapsing with the center of "image2".

-(id) initWithSpriteImage
{
    if ((self = [super initWithSpriteFrameName:@"image1.png"]))
    {

        CCSprite *image2=[CCSprite spriteWithSpriteFrameName:@"image2.png"];
    }
    return self;

}

any idea how i can solve this beside removing the init sprite?

Upvotes: 0

Views: 67

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

Assuming image2 is a child of the image1 sprite, the behavior you see is correct. I wish it were different because it is a really annoying and hard to understand behavior for beginners.

What happens is that child nodes are not centered on their parent's anchorPoint, but on the origin (0,0) of the parent's texture. So each child is centered on their parent's lower-left corner, unless the parent is a non-visual node like CCScene, CCLayer or CCNode.

Upvotes: 2

Related Questions