做一些事情" x"秒数,然后做其他事情

时间:2015-08-08 19:16:51

标签: xcode swift timer nstimer

所以我想知道什么。我有3个功能:

func makeHeroRun(){
    let heroRunAction = SKAction.animateWithTextures([ heroRun2, heroRun3, heroRun4, heroRun3], timePerFrame: 0.2)
    let repeatedWalkAction = SKAction.repeatActionForever(heroRunAction)
    hero.runAction(repeatedWalkAction)
}
func makeHeroJump(){
    let heroJumpAction = SKAction.animateWithTextures([heroJump1, heroJump2, heroJump2], timePerFrame: 0.2)
    hero.runAction(heroJumpAction)
}
func makeHeroSlide(){
    let heroSlideAction = SKAction.animateWithTextures([heroSlide1, heroSlide2], timePerFrame: 0.1)
    hero.runAction(heroSlideAction)
}

还有我的触动开始:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        var touch = touches.first as! UITouch
        var point = touch.locationInView(self.view)

        if point.x < size.width / 2 // Detect Left Side Screen Press
        {
            makeHeroSlide()
        }
        else
        if point.x > size.width / 2 // Detect Right Side Screen Press
        {
            makeHeroJump()
        }
    }

&#34;英雄&#34;是在游戏中运行的玩家。

我想要的是当&#34; makeHeroSlide&#34;已经完成了,我想重复&#34; makeHeroRun&#34;,所以在英雄滑动之后,它应该继续运行。当英雄跳跃时,它应该停止运行,当英雄击中地面时,它应该继续运行。我怎样才能做到这一点?我想要一些与&#34; Line Runner&#34;相同的功能。在AppStore中玩家跳转和滚动的游戏。

1 个答案:

答案 0 :(得分:0)

您的意思是“我希望hero通过hero.runAction()执行其他操作。

只需使用重载函数func runAction(_ action: SKAction, completion block: () -> Void)

https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKNode_Ref/index.html#//apple_ref/occ/instm/SKNode/runAction:completion

e.g。

hero.runAction(heroSlideAction) { 
    /* completion block goes here. Takes no input, returns nothing. */
    hero.runAction(someOtherAction)
}