【问题标题】:SKAction not working properlySKAction 无法正常工作
【发布时间】:2014-08-17 17:25:08
【问题描述】:

我有一系列想要播放的 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];

}

【问题讨论】:

    标签: ios objective-c sprite-kit skaction sknode


    【解决方案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];
    

    【讨论】:

    • 那么我在哪里可以使用它?
    猜你喜欢
    • 2015-01-04
    • 2016-12-01
    • 1970-01-01
    • 2016-09-01
    • 2012-07-11
    • 2018-04-08
    • 2017-04-20
    • 2018-10-02
    • 2016-09-04
    相关资源
    最近更新 更多