2015-07-01 150 views
0

我想向我的SpriteKit場景添加一個轉換,但它不起作用。我的第二個場景叫做「myScene」。這是我的代碼:SpriteKit轉換不起作用

func didBeginContact(contact: SKPhysicsContact) { 
    let collision:UInt32 = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask) 

    if collision == (playerCategory | crateCategory) { 

     NSLog("Game Over") 
     self.scene?.view?.paused = true 
     var myscene = myScene(size: self.size) 
     var transition = SKTransition.doorsCloseHorizontalWithDuration(0.5) 
     myscene.scaleMode = SKSceneScaleMode.AspectFill 
     self.scene!.view?.presentScene(myscene, transition: transition) 

    } 
    if (contact.bodyA.categoryBitMask == bubbleCategory) { 
     let node = contact.bodyB.node 
     //Other remove routine 
     node?.removeAllActions() 
     node?.removeFromParent() 
    } else if (contact.bodyB.categoryBitMask == bubbleCategory) { 
     let node = contact.bodyB.node 
     //Other remove routine 
     node?.removeAllActions() 
     node?.removeFromParent() 
    } 


} 

這裏有什麼問題?

回答

0

這將呈現現場,它每次都適合我。這不會爲場景返回零,因此它將平穩過渡。您還可以設置ignoreSiblingOrder到任何你想要的這條線:skView?.ignoresSiblingOrder = true //or false 這裏是我的GameScene:

class GameScene: SKScene { 
override func didMoveToView(view: SKView) { 
    self.backgroundColor = UIColor.redColor() 
} 

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

    for touch in (touches as! Set<UITouch>) { 
     let location = touch.locationInNode(self) 
     println("touch occured in gamescene") 

     let scene:SKScene = myScene() 
     let skView = self.view as SKView? 
     skView!.ignoresSiblingOrder = true 
     scene.scaleMode = .AspectFill 
     scene.size = skView!.bounds.size 
     skView!.presentScene(scene) 


    } 
} 

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

}

+0

評論不適合廣泛的討論;這個對話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/82223/discussion-on-answer-by-the-codecomposer-spritekit-transition-wont-work)。 – Taryn