如何在 spritekit 中向节点添加滑动手势 [英] How to add a swipe gesture to a node in spritekit
本文介绍了如何在 spritekit 中向节点添加滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向节点添加滑动手势,以便当用户滑动它时,它会离开屏幕,但我不断收到 SIGABRT
错误:
I'm trying to add a swipe gesture to a node so that when a user swipes it, it goes off screen but I keep getting a SIGABRT
error:
`Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'`
我不确定为什么会弹出此错误.我确保在 .sks
文件中正确标记了节点.这是我的代码:
I'm not sure why this error is popping up. I made sure the node is labeled correctly in the .sks
file. Here is my code:
import SpriteKit
let plankName = "woodPlank"
class PlankScene: SKScene {
var plankWood : SKSpriteNode?
override func didMove(to view: SKView) {
plankWood = childNode(withName: "woodPlank") as? SKSpriteNode
let swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:"))
swipeRight.direction = .right
view.addGestureRecognizer(swipeRight)
}
func swipedRight(sender: UISwipeGestureRecognizer) {
print("Object has been swiped")
}
func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent)
{
let touch = touches.first as! UITouch
let location = touch.location(in: self)
if (plankWood?.frame.contains(location))!
{
print("Swipe has started")
}
}
}
推荐答案
遇到了同样的问题,所以我们对此有一个公认的答案我想指出 0x141E
留下的评论是解决这个问题的正确方法:
Had the same problem, just so we have an accepted answer on this I would like to point out that the comment left by 0x141E
is the correct solution to this:
将 Selector("swipedRight:")
替换为 #selector(PlankScene.swipedRight)
这篇关于如何在 spritekit 中向节点添加滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文