gpt4 book ai didi

swift - 如何在swift SKSpriteNode中添加按钮效果

转载 作者:行者123 更新时间:2023-11-28 13:13:40 25 4
gpt4 key购买 nike

我有一个 Var 按钮。

var soundButton: SKSpriteNode! = nil

细节是一样的。

soundButton           =   SKSpriteNode(imageNamed: "\(soundImg)")
soundButton.position = CGPoint(x: frame.size.width*0.08 , y:frame.size.width*0.08);
soundButton.size = CGSizeMake(frame.size.width*0.10,frame.size.width*0.10 )
self.addChild(soundButton)

当我点击它并发出声音时,如何添加按钮效果,如按钮颜色灯。

最佳答案

一种方法是您可以在选择按钮时更改图像。

像这样进入您的 touchesBegan 方法:

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)

if self.nodeAtPoint(location) == self. soundButton {
soundButton.texture = SKTexture(imageNamed: "soundSelected")

}
}
}

如果你想延迟到另一个场景并且你想要转换你可以在你的 if 语句中使用这个代码:

let reveal = SKTransition.flipHorizontalWithDuration(0.5)
let letsPlay = playScene(size: self.size)
self.view?.presentScene(letsPlay, transition: reveal)

关于swift - 如何在swift SKSpriteNode中添加按钮效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30206766/

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