在调用SKView暂停之前添加SKNode

时间:2014-11-11 10:36:11

标签: swift ios8 sprite-kit

我试图在暂停场景之前添加SKSpriteNode。但是目前我的代码中的场景暂停得很快,以至于没有时间用新的SKSpiteNode渲染帧。在场景未暂停后,将出现SKSpriteNode。在场景暂停之前,我怎么能保证SKSpriteNode是渲染的。这是我的代码:

func pauseScene() {

    if (self.scene?.view?.paused == true){
        self.pauseNode.removeFromParent()
        self.scene?.view?.paused = false
    } else if (self.scene?.view?.paused == false){
        pauseTexture = SKTexture(imageNamed: "pauseImage")
        pauseTexture.filteringMode = SKTextureFilteringMode.Nearest
        pauseNode = SKSpriteNode(texture: pauseTexture)
        pauseNode.zPosition = 100
        pauseNode.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
        pauseNode.size = CGSize(width: screenSize.width, height: screenSize.height)
        self.addChild(pauseNode)
        self.scene?.view?.paused = true
    }

}

0 个答案:

没有答案