简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM