gpt4 book ai didi

ios - 如何为spritekit中的节点添加滑动手势

转载 作者:搜寻专家 更新时间:2023-11-01 06:18:08 24 4
gpt4 key购买 nike

我正在尝试向节点添加滑动手势,以便当用户滑动它时,它会离开屏幕,但我一直收到 SIGABRT 错误:

`Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'`

我不确定为什么会弹出此错误。我确保节点在 .sks 文件中被正确标记。这是我的代码:

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 留下的评论是正确的解决方案:

Selector("swipedRight:") 替换为 #selector(PlankScene.swipedRight)

关于ios - 如何为spritekit中的节点添加滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39783608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com