【发布时间】:2014-12-31 19:40:09
【问题描述】:
就像我在应用商店中找到的许多其他应用一样,当您触摸一个按钮时,它会以某种方式缩放,无论它变大还是变小。我想使用SpriteKit 节点和SKAction 来实现这一点; scaleTo。这是我到目前为止所得到的。
import SpriteKit
class GameEndedScene: SKScene {
let scaleIn = SKAction.scaleTo(1.5, duration: 0.2)
let scaleOut = SKAction.scaleTo(1.0, duration: 0.2)
override func didMoveToView(view: SKView) {
/* Setup your scene here */
var playButton = SKSpriteNode()
var shareButton = SKSpriteNode()
playButton.size = CGSizeMake(100, 100)
shareButton.size = CGSizeMake(100, 100)
playButton.position = CGPointMake(self.frame.midX, self.frame.midY + 100)
shareButton.position = CGPointMake(self.frame.midX, self.frame.midY - 100)
playButton.color = UIColor.whiteColor()
shareButton.color = UIColor.whiteColor()
playButton.name = "Scale"
shareButton.name = "Scale"
addChild(playButton)
addChild(shareButton)
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node: SKNode = nodeAtPoint(location)
if node.name == "Scale" {
node.runAction(scaleIn)
}
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node: SKNode = nodeAtPoint(location)
if node.name == "Scale" {
node.runAction(scaleOut)
}
}
}
缩放在touchesBegan 和touchesEnded 中工作得非常好,但我希望用户能够移动触摸,并且如果它开始触摸一个新节点,该节点也以“Scale”为名,我想要它具有与 Touches Began 相同的效果,如果触摸远离节点,我希望它具有与 touchesEnded 相同的效果。感谢您的帮助,抱歉之前是凌晨 3:00,所以没有详细说明。
【问题讨论】:
-
请拨打tour 并阅读How to Ask,了解我们对问题的期望。以目前的形式,您的问题无法回答,因为它太宽泛了。请收集更多信息,然后edit您的帖子。
-
抱歉,已更新。
标签: swift sprite-kit skaction touchesmoved