首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在快速SKSpriteNode中添加按钮效果

如何在快速SKSpriteNode中添加按钮效果
EN

Stack Overflow用户
提问于 2015-05-13 05:57:40
回答 1查看 530关注 0票数 0

我有个Var Button

代码语言:javascript
复制
var soundButton: SKSpriteNode! = nil

细节就像。

代码语言:javascript
复制
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)

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-13 06:12:45

这样做的一种方法是,您可以在选择按钮时更改图像。

像这样进入您的touchesBegan方法:

代码语言:javascript
复制
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语句中使用以下代码:

代码语言:javascript
复制
let reveal = SKTransition.flipHorizontalWithDuration(0.5)
let letsPlay = playScene(size: self.size)
self.view?.presentScene(letsPlay, transition: reveal)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30206766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档