Swift&x2B;SpriteKit-检测长压头
我试图找出如何检测用户何时停止按下按钮。我试图让背景连续滚动,并设置角色动画以模拟行走效果 要移动背景,我在游戏场景中有这个。Swift:Swift&x2B;SpriteKit-检测长压头,swift,sprite-kit,uigesturerecognizer,Swift,Sprite Kit,Uigesturerecognizer,我试图找出如何检测用户何时停止按下按钮。我试图让背景连续滚动,并设置角色动画以模拟行走效果 要移动背景,我在游戏场景中有这个。Swift: override func update(currentTime: NSTimeInterval) { background.position = CGPoint(x: background.position.x - 5, y: background.position.y) backgroundRepeated.posit
override func update(currentTime: NSTimeInterval) {
background.position = CGPoint(x: background.position.x - 5, y: background.position.y)
backgroundRepeated.position = CGPoint(x: backgroundRepeated.position.x - 5, y: backgroundRepeated.position.y)
if (background.position.x < -background.size.width) {
background.position = CGPointMake(backgroundRepeated.position.x + backgroundRepeated.size.width, background.position.y)
}
if (backgroundRepeated.position.x < -backgroundRepeated.size.width) {
backgroundRepeated.position = CGPointMake(background.position.x + background.size.width, backgroundRepeated.position.y)
}
}
然后我将上面的代码包装在一个if中:
let startWalking = gameActions.boolForKey("Walking")
if (startWalking == true) {
//stuff to animate
}
我的问题
1)如何检测用户何时停止按下按钮。我看到了uigesturecognizer。结束了,但我看不到如何实现它。不确定
uigesturecognizer
是否是您想要的,您的按钮是ui按钮
还是SpriteKit
中的SKNode
我是新手,因此非常感谢您的帮助:)然后只需为内部触地创建一个iAction,当您开始按下内部触地按钮iAction时,即松开按钮,您可能需要在外部进行润色,您需要覆盖函数touchesend(touchs:Set,withEvent-event:UIEvent?
以及列出的其他内容?@LandSeagull您好,谢谢您的回复。老实说,我不确定我需要什么。我想要的是:当用户按住UIButton或SKNode图像时,将启动一个函数。当用户将手指从按钮/节点上取下时,我希望运行另一个函数。这有意义吗?
let startWalking = gameActions.boolForKey("Walking")
if (startWalking == true) {
//stuff to animate
}