如何检测是否触摸了SKShapeNode? [英] How can you detect if SKShapeNode is touched?
本文介绍了如何检测是否触摸了SKShapeNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个sknodeshape.如何检测(触摸)我制作的形状是否被触摸?
I created a sknodeshape. How can I detect if the shape I made was touched(clicked)?
下面是代码:(我已经解决了)
Here is the code: (I solved it already)
//metung_babi is the name of the SKShapeNode
UITouch *touch = [touches anyObject];
CGPoint nokarin = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:nokarin];
if ([node.name isEqualToString:@"metung_babi"]) {
NSlog(@"touch me not");
}
我的错误是在创建形状时,我在初始化形状之前放了SKShapeNode名称.
my mistake was when I created the shape I put the SKShapeNode name before initializing it.
推荐答案
实现触摸委托方法.然后,在-touchesBegan:方法中,提取触摸点并使用[self nodeAtPoint:]方法检索节点
Implement the touch delegate methods. Then, in the -touchesBegan: method, extract the point of touch and retrieve the node using the [self nodeAtPoint:] method
这篇关于如何检测是否触摸了SKShapeNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文