gpt4 book ai didi

ios - SKNode : Converting Coordinates from UIView to SKNode 上的 UITapGestureRecognizer

转载 作者:可可西里 更新时间:2023-11-01 03:37:08 26 4
gpt4 key购买 nike

我在带有 SKSceneUIView 上有一个 UITapGestureRecognizer 和一个 UIPanGestureRecognizer。平移手势识别器从左到右移动一个 SKNode,我希望 Tap 手势识别器检测平移的 SKNode 的子节点。平移工作正常,但我在检测点击时遇到问题 - Tap Gesture 触发了相关方法,但我不确定如何将坐标从 View 转换为场景到节点以检测点击是否在其中之一子节点。

UIView(带手势)→ SKScene → 平移节点 → 平移节点的子节点

如何检查点击手势的触摸坐标是否是任何给定的 SKNode?

-(void)tapAction:(UITapGestureRecognizer*)sender{
if (sender.state == UIGestureRecognizerStateEnded)
{
// handling code
CGPoint touchLocation = [sender locationOfTouch:0 inView:sender.view];
NSLog(@"TAP %@", NSStringFromCGPoint(touchLocation)
);
for (SKLabelNode *node in _containerNode.children) {

if ([node containsPoint:[node convertPoint:touchLocation fromNode:self.parent]]) {
//This is where I want the tap to be detected.
}

CGPoint checkPoint = [node convertPoint:touchLocation fromNode:self.scene];
NSLog(@"CheckPoint %@", NSStringFromCGPoint(checkPoint)
);
//NSLog(@"iterating nodes");
if ([node containsPoint:checkPoint]) {
NSLog(@"touch match %@", node);

}
}
}

最佳答案

最后,我需要根据建议执行更多步骤 - 从 SKView → SKScene 转换为包含我进行 HitTest 的节点的 SKNode。

    CGPoint touchLocation           = [sender locationOfTouch:0 inView:sender.view];
CGPoint touchLocationInScene = [[self.scene view] convertPoint:touchLocation toScene:self.scene];
CGPoint touchLocationInNode = [self.scene convertPoint:touchLocationInScene toNode:_containerNode];

关于ios - SKNode : Converting Coordinates from UIView to SKNode 上的 UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29110944/

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