оживить движущийся спрайт - PullRequest
1 голос
/ 16 октября 2011

я знаю, как анимировать спрайт с помощью 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];

}

1 Ответ

0 голосов
/ 24 октября 2011

Вы должны изменить анимацию для ходьбы, когда она начинает двигаться, и изменить, когда остановка в [sprite runAction: sequence];

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...