【发布时间】:2015-01-07 07:16:23
【问题描述】:
我试图弄清楚如何检测我是否触摸了精灵套件中的节点。我认为它在 UIView 中是这样的功能:
[myView pointInside:point withEvent:nil];
但到目前为止,我还没有找到替代方案。我想要完成的是知道我已经触摸了屏幕中的精灵节点。
如果你能帮我完成这个,我将不胜感激
这是我的代码中的内容。我正在添加动画节点:
-(void)addMyNodeAnimated
{
NSMutableArray *myNodeArray = [NSMutableArray array];
NSArray *animatedFrames = [NSArray new];
SKTextureAtlas *AnimatedAtlas = [SKTextureAtlas atlasNamed:@"pc2"];
int numImages = (int)AnimatedAtlas.textureNames.count;
for (int i=1; i <= numImages; i++) {
NSString *textureName = [NSString stringWithFormat:@"%@-%d", @"pc2", i];
SKTexture *temp = [AnimatedAtlas textureNamed:textureName];
[myNodeArray addObject:temp];
}
animatedFrames = myNodeArray;
SKTexture *temp = animatedFrames[0];
SKSpriteNode *animationNode = [SKSpriteNode spriteNodeWithTexture:temp];
animationNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
animationNode.userInteractionEnabled = YES;
animationNode.name = @"AnimationNode";
[self addChild:animationNode];
[animationNode runAction:[SKAction repeatActionForever:
[SKAction animateWithTextures:animatedFrames
timePerFrame:0.1f
resize:NO
restore:YES]] withKey:@"AnimationRuning"];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint _touchLocation = [[touches anyObject] locationInNode:self];
SKNode *node = [self nodeAtPoint:_touchLocation];
if (node != nil)
{
NSLog(@"node name %@", node.name);
}
}
当我触摸屏幕中的节点时,节点返回 null。
有人知道这是为什么吗?
【问题讨论】:
标签: ios ios7 touch sprite-kit