2016-01-09 195 views
0

我的代碼在這裏出了什麼問題?我正在嘗試從GameScene轉換到ActionScene。在模擬器中,沒有響應對精靈的觸摸。請幫忙!!SpriteKit場景轉換XCode 7

import SpriteKit 

class GameScene: SKScene { 
    override func didMoveToView(view: SKView) { 
     /* Setup your scene here */ 
     let sprite = SKSpriteNode(imageNamed:"Spaceship") 

     sprite.xScale = 0.5 
     sprite.yScale = 0.5 
     sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) 


     self.addChild(sprite) 
    } 

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
     /* Called when a touch begins */ 

     for touch in touches { 
      let location = touch.locationInNode(self) 
      let touchedNode = nodeAtPoint(location) 

      if touchedNode.name == "sprite" { 
       let transition = SKTransition.revealWithDirection(.Down, duration: 0.5) 

       let ActionScene = GameScene(size:scene!.size) 

       ActionScene.scaleMode = .AspectFill 

       scene?.view?.presentScene(ActionScene, transition: transition) 
      } 


     } 
    } 

    override func update(currentTime: CFTimeInterval) { 
    /* Called before each frame is rendered */ 
    } 
} 

回答

1

您初始化您的ActionScene錯誤。如果你想轉換到ActionScene,你不能初始化GameScene(因爲我假設你已經在GameScene上並正在嘗試轉換到actionScene)。所以這段代碼

let actionScene = GameScene(size:scene!.size) 

改變這種

let actionScene = ActionScene(size:scene!.size) 
+0

我想過渡到動作場面。切換不起作用,因爲沒有場景:actionScene,我不能使用* let ActionScene = ActionScene *,因爲它給了我一個錯誤。 @Dieblitzen – JOSH

+0

所以你還沒有創建一個ActionScene?如果你還沒有創建一個場景,那麼你希望如何過渡到它?我建議你創建一個名爲ActionScene的新文件,它是SKScene的一個子類,以便你可以轉換到它。 – Dieblitzen