gpt4 book ai didi

ios - 检测触摸是否在 Sprite 边界内,但忽略 child

转载 作者:行者123 更新时间:2023-11-28 06:50:12 35 4
gpt4 key购买 nike

我有一个 sprite,我需要检测是否在它的范围内进行了触摸。通常只使用下面的代码就可以了,但是我当前的 sprite 有 child 在 sprite 的边界之外。因此,我的触摸是在父边界之外检测到的,因为 Sprite 边界似乎包括它的子边界。有谁知道如何检测是否仅对 parent (而不是 child )进行了触摸?

 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

let touch = touches.first as UITouch!
var touchLocation = touch.locationInNode(self)

if mySprite.containsPoint(touchLocation) {

// Do Something

}

}

最佳答案

尝试检查 touchLocation 是否在 mySprite 的框架内,如下所示:

if CGRectContainsPoint(mySprite.frame, touchLocation) {
// Do something
}

关于ios - 检测触摸是否在 Sprite 边界内,但忽略 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35109991/

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