1

我有一系列想要播放的 SKAction,但它们无法正常播放。眼睛只会闭上,再也不会睁开。我不知道为什么会发生这种情况,但也许你会!感谢您的帮助,谢谢。

-(void)blink {

    SKAction *delay = [SKAction waitForDuration:3];
    SKAction *blinkEye = [SKAction resizeToHeight:1 duration:.2];
    SKAction *delay2 = [SKAction waitForDuration:.5];
    SKAction *openEye = [SKAction resizeToHeight:3 duration:.2];

    SKAction *group1 = [SKAction group:@[delay,blinkEye]];
    SKAction *group2 = [SKAction group:@[delay2,openEye]];

    SKAction *all = [SKAction sequence:@[group1,group2]];

    SKAction *repeat = [SKAction repeatActionForever:all];

    [self runAction:repeat];

}

在 MyScene.m 中

-(void)update:(CFTimeInterval)currentTime {
 /* Called before each frame is rendered */
    Player *player = (Player *)[self childNodeWithName:@"player"];
    Player *lefteye = (Player *)[player childNodeWithName:@"leye"];
    Player *righteye = (Player *)[player childNodeWithName:@"reye"];
    [lefteye blink];
    [righteye blink];

}
4

1 回答 1

1

不需要分组,它会导致问题。

SKAction *delay = [SKAction waitForDuration:3];
SKAction *blinkEye = [SKAction resizeToHeight:1 duration:.2];
SKAction *delay2 = [SKAction waitForDuration:.5];
SKAction *openEye = [SKAction resizeToHeight:3 duration:.2];

SKAction *all = [SKAction sequence:@[delay,blinkEye, delay2,openEye]]];

并且让每帧更新都眨眼是行不通的。该函数每秒最多调用 60 次。

而是在创建眼睛对象时这样做:

SKAction *delay = [SKAction waitForDuration:3];
SKAction *blinkEye = [SKAction resizeToHeight:1 duration:.2];
SKAction *delay2 = [SKAction waitForDuration:.5];
SKAction *openEye = [SKAction resizeToHeight:3 duration:.2];

SKAction *all = [SKAction sequence:@[delay,blinkEye, delay2,openEye]]];

//create the lefteye object
lefteye = [[Eye alloc] init...]; 
//create the righteye object
righteye = [[Eye alloc] init...];
[lefteye repeatActionForever:all];
于 2014-08-17T17:27:20.847 回答