功能完成后执行某些操作

时间:2015-08-09 14:56:09

标签: ios swift sprite-kit

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

set.seed(24)
dat <- data.frame(a=runif(5), b=runif(5), c=runif(5), d=runif(5))

还有我的触动开始:

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)
}

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

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

1 个答案:

答案 0 :(得分:1)

您可以使用runAction作为第二个参数调用completion:函数,您可以使用该参数指定在执行操作后执行的块。

hero.runAction(heroSlideAction, completion: {() -> Void in
    // do something here
})