gpt4 book ai didi

ios - 如何让 startScene 上的按钮转到 GameScene

转载 作者:行者123 更新时间:2023-11-29 01:23:16 27 4
gpt4 key购买 nike

我想制作一个按钮,将我从我的 startScene 带到我的 GameScene。我发现的所有内容都是在我单击屏幕而不是按钮时发生转换。这是我发现的,但没有用。想法?

    var startButton = SKNode()

override func didMoveToView(view: SKView) {
/* Setup your scene here */

startButton = SKSpriteNode(color: SKColor.redColor(), size: CGSize(width: 100, height: 50))
startButton.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
self.addChild(startButton)

}

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

let gameSceneTransition = GameScene(fileNamed: "GameScene")
let touch = touches
let location = touch.first!.locationInNode(self)
let node = self.nodeAtPoint(location)

// If next button is touched, start transition to second scene
if (node.name == "startButton") {
self.scene?.view?.presentScene(gameSceneTransition!, transition: SKTransition.fadeWithDuration(1.0))
}

}

最佳答案

如果要比较节点的名称,则需要设置节点的 name 属性。简单地说:

var startButton = SKNode()

不设置节点的名称属性。你最多也说

startButton.name = "startButton"

你可以直接说

if node == startButton
{
self.scene?.view?.presentScene(gameSceneTransition!, transition: SKTransition.fadeWithDuration(1.0))
}

关于ios - 如何让 startScene 上的按钮转到 GameScene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347343/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com