【发布时间】:2016-02-23 05:44:06
【问题描述】:
我有一个尺寸减小到 0.8 的精灵。当我使用 sprite.ContainsPoint(touchLocation) 时,触摸只在原始大小精灵的 0.8 范围内注册(这是有道理的)。然而,即使精灵已经缩小,我仍然希望触摸注册,就好像精灵仍然是全尺寸(1.0)。以下是我当前的代码:
var button: SKSpriteNode!
func createButton() {
button = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(100, 100))
addChild(button)
button.runAction(SKAction.scaleTo(0.8, duration: 1))
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first as UITouch!
let touchLocation = touch.locationInNode(self)
if button.containsPoint(touchLocation) {
print("touching within the button")
}
}
我尝试过哪些不起作用,但您可能会看到我正在尝试做的事情:
var button: SKSpriteNode!
func createButton() {
button = SKSpriteNode(color: UIColor.redColor(), size: CGSizeMake(100, 100))
addChild(button)
button.runAction(SKAction.scaleTo(0.8, duration: 1))
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first as UITouch!
let touchLocation = touch.locationInNode(self)
let myButton = CGRectMake(button.position.x, button.position.y, button.size.width / 0.8, button.size.width / 0.8)
//// the button.size / 0.8 should bring the size back to 1.0
if myButton.containsPoint(touchLocation) {
print("touching within the button")
}
}
任何帮助都会很棒!
【问题讨论】:
标签: swift sprite-kit sprite contains touches