简体   繁体   English

cocos2d ccsprite动画

[英]cocos2d ccsprite animation

Im working on an app for the iphone and i am new to cocos2d and objective c. 我正在为iPhone开发应用程序,我是cocos2d和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. 胜利的眼睛png为240x38,所以3帧为80x38对我来说似乎是正确的。 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 这是我的第一个应用程序,因此假设我一无所知,任何人都无法想到我可能已经看过的任何东西,谢谢G

Take a look at blend modes: 看一下混合模式:

cocos2d FAQ cocos2d常见问题

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... 但是,如果仍然存在,您可能需要发布一些屏幕截图,因为我不确定我是否确切理解了您的意思...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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