2015-08-08 50 views
0

所以我想知道一些事情。我有3个功能:做一些“x”秒的时间,然后做点别的事

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

,也是我的touchesBegan:

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

“英雄” 是在游戏运行播放器。

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

+0

什么是'heroRunAction'? – s1ddok

回答

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

例如

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