【问题标题】:SKSpriteNode selector with interval带间隔的 SKSpriteNode 选择器
【发布时间】:2013-10-31 18:47:53
【问题描述】:

SpriteKit 相当于什么?

[CCNode schedule:@selector(doActivate)
        interval:[[enemyData objectForKey:@"spawnTime"] floatValue]];

【问题讨论】:

    标签: ios7 sprite-kit


    【解决方案1】:

    您可以使用 SKAction 来执行此操作:

    + (SKAction *)performSelector:(SEL)selector onTarget:(id)target or 
    
    + (SKAction *)runBlock:(dispatch_block_t)block queue:(dispatch_queue_t)queue
    

    结合:

    + (SKAction *)repeatActionForever:(SKAction *)action
    

    + (SKAction *)waitForDuration:(NSTimeInterval)sec
    

    每次通话之间的延迟

    【讨论】:

    • 自己构建计时器?这些助手实际上并没有转化为 Cocos 等价物。
    • 我进行了编辑以计算“计时器”,也就是延迟。这是“SpriteKit”最接近的。您唯一的其他选择是使用更通用的 iOS 方法在计时器上运行块或选择器。
    • performSelector:afterDelay: 也可以,尽管这是基于时间而不是基于帧的。
    【解决方案2】:

    Cocos 中的调度器:

    [self schedule:@selector(doActivate:)
          interval:[[enemyData objectForKey:@"spawnTime"] floatValue]];
    

    在 Spritekit 中使用 SKAction 等效:

    SKAction *wait = [SKAction waitForDuration:[[enemyData objectForKey:@"spawnTime"] floatValue]];
    SKAction *performSelector = [SKAction performSelector:@selector(doActivate:) onTarget:self];
    SKAction *sequence = [SKAction sequence:@[performSelector, wait]];
    SKAction *repeat   = [SKAction repeatActionForever:sequence];
    [self runAction:repeat];
    

    【讨论】:

      猜你喜欢
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多