0

按照建议对我的代码进行调整后,我的动画现在可以工作了。现在,我想问一下如何反转精灵的动作。我试图让精灵移动,就好像风在里面一样。这是我现在的代码:

-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super init]) ) {
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    self.isTouchEnabled = YES;

    CCSprite *black = [CCSprite spriteWithFile:@"b.png"];
    black.position = ccp(100, 160);
    black.scaleX = 100 / black.contentSize.width;
    black.anchorPoint = ccp(0.03, 0);

    CCSpriteFrameCache *frame = [CCSpriteFrameCache sharedSpriteFrameCache];
    [frame addSpriteFramesWithFile:@"bLongAnimation.plist"];
    CCSpriteBatchNode *bHair = [CCSpriteBatchNode batchNodeWithFile:@"bLongAnimation.png"];
    [self addChild:bHair];

    [self addChild:black z:1 tag:1];

    //Animation
    NSMutableArray *animateBlackHair = [NSMutableArray arrayWithCapacity:10];
    for (int i = 1; i < 10; i++)
    {
        NSString *animBlackHair = [NSString stringWithFormat:@"b%i.png", i];
        CCSpriteFrame *blackFrame = [frame spriteFrameByName:animBlackHair];
        [animateBlackHair addObject:blackFrame];

        //I added this code block thinking it might work
        for(i = 10; i > 1; i--)
        {
            NSString *revAnimation = [NSString stringWithFormat:@"bRightLong%i.png", i];
            CCSpriteFrame *revFrame = [frame spriteFrameByName:revAnimation];
            [animateBlackHair1 addObject:revFrame];
        }
    }
    CCAnimation *blowHair = [CCAnimation animationWithSpriteFrames:animateBlackHair delay:0.1];
    CCAction *blowingHair = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:blowHair]];
    [black runAction:blowingHair];        
}
return self;}

我的猜测没有奏效,所以我想知道如何在完成第一个动作后立即反转动作?

更新:没关系,我想通了。我只是移动了 for 循环,以便在另一个循环之外反转动作。感谢您的帮助。

4

1 回答 1

2

尝试将动画的延迟设置为 0 以外的值。尝试 0.1 或 0.4 或其他值。如果您将其设置为零,我认为动画不会运行,如果运行,它会运行得太快而无法看到。

于 2013-02-01T02:53:35.593 回答