Cocos2d iphone 为移动的精灵设置动画

Cocos2d iphone 为移动的精灵设置动画,cocos2d-iphone,Cocos2d Iphone,我知道如何使用cocos2d和spritesheet和plist制作精灵动画 我有一个世界,当施力时,精灵可以在这个世界上移动 我需要设置那个精灵的动画,当它在移动时,比如说它摔倒了,所以当它摔倒或移动时,它的眼睛应该是眨眼的 我现在的动画代码是这样的,当我插入一个新的精灵,但我需要将它应用到一个特定的精灵,而不是一个特定的地方 -(void)animation:(NSString *)animation { [[CCSpriteFrameCache sharedSpriteFram

我知道如何使用cocos2d和spritesheet和plist制作精灵动画

我有一个世界,当施力时,精灵可以在这个世界上移动

我需要设置那个精灵的动画,当它在移动时,比如说它摔倒了,所以当它摔倒或移动时,它的眼睛应该是眨眼的

我现在的动画代码是这样的,当我插入一个新的精灵,但我需要将它应用到一个特定的精灵,而不是一个特定的地方

-(void)animation:(NSString *)animation
{


    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist",animation]];
    sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@_00000.png",animation]]; //take the corrdinates of this picture from the plist

    //sprite.position=ccp(240,160);
    //sprite.position=ccp(160,175);

    CCSpriteBatchNode *spriteSheet = [ CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"%@.png",animation]];
    [spriteSheet addChild:sprite]; //add this coordinates from the spritesheet to the screen
    [self addChild:spriteSheet];


    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *animPath = [Path stringByAppendingPathComponent: [NSString stringWithFormat:@"%@.plist", animation]];
    NSDictionary *animSpriteCoords = [[NSDictionary alloc] initWithContentsOfFile: animPath];
    NSDictionary *animFramesData = [animSpriteCoords objectForKey:@"frames"];
    int b=0;
    int a=0;
    NSMutableArray *animFrames = [NSMutableArray array];
    for(int i = 1; i < [animFramesData count]; i++) 

    {
        a=a+1;
        if(a==10)
        {
            b=b+1;
            a=0;
        }

        CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@_000%0i%1i.png",animation,b,a]];   //[NSString stringWithFormat:@"eye_blinking_0000%1d.png",i]
        [animFrames addObject:frame];
    }

    CCAnimate *Action ;
    CCAnimation* dollAnimation = [CCAnimation animationWithFrames:animFrames delay:0.1f];
    Action = [CCAnimate actionWithAnimation:dollAnimation];
    id call=[CCCallFunc actionWithTarget:self selector:@selector(finishAnimation)];
    id sequence=[CCSequence actions:Action,[CCHide action],call,nil];
    [sprite runAction:sequence];

}
-(void)动画:(NSString*)动画
{
[[CCSpriteFrameCache sharedSpriteFrameCache]添加SpriteFrameSwithFile:[NSString stringWithFormat:@“%@.plist”,动画]];
sprite=[CCSprite SPRITEWITHPRITEFRAMENAME:[NSString stringWithFormat:@“%@00000.png”,动画]];//从plist获取此图片的相关内容
//精灵位置=ccp(240160);
//精灵位置=ccp(160175);
CCSpriteBatchNode*spriteSheet=[CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@“%@.png”,动画]];
[spriteSheet addChild:sprite];//将此坐标从spriteSheet添加到屏幕
[自添加子项:精灵表];
NSString*Path=[[NSBundle mainBundle]bundlePath];
NSString*animPath=[Path stringByAppendingPathComponent:[NSString stringWithFormat:@“%@.plist”,动画]];
NSDictionary*animSpriteCoords=[[NSDictionary alloc]initWithContentsOfFile:animPath];
NSDictionary*animsframesdata=[animSpriteCoords objectForKey:@“frames”];
int b=0;
int a=0;
NSMutableArray*animFrames=[NSMutableArray];
对于(int i=1;i<[animFramesData count];i++)
{
a=a+1;
如果(a==10)
{
b=b+1;
a=0;
}
CCSpriteFrame*frame=[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:[NSString stringWithFormat:@“%@_000%0i%1i.png”,动画,b,a]];/[NSString stringWithFormat:@“eye_blinking_0000%1d.png”,i]
[动画帧添加对象:帧];
}
cAnimate*行动;
cAnimation*dollAnimation=[cAnimation animationWithFrames:AnimationFrames延迟:0.1f];
动作=[cAnimate actionWithAnimation:dollAnimation];
id call=[CCCallFunc actionWithTarget:self-selector:@selector(finishAnimation)];
id序列=[CCSequence actions:Action,[CCHide Action],call,nil];
[精灵运行操作:序列];
}

在[sprite runAction:sequence]中,当动画开始移动时,必须将动画更改为walk,当动画停止时,必须更改动画