views:

125

answers:

1

Hey all Im working on an app for the iphone and i am new to cocos2d and objective c. Im having some trouble getting a sprite animation to be position as i want it. I have a background sprite and have a second animation sprite that goes over it. In this case the background is a person and the animation sprite is the eyes blinking.

CGSize winSize = [[CCDirector sharedDirector] winSize];

        CCSprite * bg = [CCSprite spriteWithFile:@"victory.png"];
        [bg setPosition:ccp(240, 160)];
        [self addChild:bg z:0];

        kidSheetBlinking = [CCSpriteSheet spriteSheetWithFile:@"victory_eyes.png"];
        [self addChild:kidSheetBlinking z:0];

        // create the sprite
        kidSpriteBlinking = [CCSprite spriteWithTexture:kidSheetBlinking.texture rect:CGRectMake(0, 0, 80, 38)];
        [kidSheetBlinking addChild:kidSpriteBlinking];

        kidSpriteBlinking.position = ccp(winSize.width/2+15,winSize.height/2+62);

        // create the animation
        kidBlinking1 = [CCAnimation animationWithName:@"blinking1" delay:0.1f];

        for (int x = 2; x > 0; x--) {
            CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:kidSheetBlinking.texture rect:CGRectMake(x*80,0*38,80,38) offset:ccp(0,0)];
            [kidBlinking1 addFrame:frame];

        }

        for (int x = 0; x < 3; x++) {
            CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:kidSheetBlinking.texture rect:CGRectMake(x*80,0*38,80,38) offset:ccp(0,0)];
            [kidBlinking1 addFrame:frame];


        }


        // create the action
        kidBlinkingAction1 = [CCAnimate actionWithAnimation:kidBlinking1 ];
        id play = [CCCallFunc actionWithTarget:self selector:@selector(onKidAnimEnd)];

        // run the action
        [kidSpriteBlinking runAction:[CCSequence actions:kidBlinkingAction1,play, nil]];

the victory eyes png is 240x38 so have the 3 frames being 80x38 seems correct to me. but for some reason I cant get the animation to line up correctly with the image below it. there seems to be a thin line around the sprite animation too. I have tried moving the sprite around many times to line it up so it cant be just a simple matter of repositioning it. I have to be missing something else. any ideas would be great. this is my first app so assuming i know nothing can anyone think of anything that i may have over looked thanks G

A: 

Take a look at blend modes:

cocos2d FAQ

Scroll down to troubleshooting and check the three blend mode examples - maybe this will solve your problem with the thin line around the sprite.

As to the positioning problem, if appears to be missaligned by only one pixel, maybe it is a related problem. However if it persists, you might want to post some screenshots, as I'm not sure I understood exactly what you mean...

Toastor