基本上,我有一个对象随机出现然后淡出,目的是点击对象使其消失.
但是我似乎无法点击该对象,即使我设置了mySKSpriteNode.userInteractionEnabled = YES;
这是我在touchesBegan方法中所拥有的:
-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ NSLog(@"Something was touched"); UItouch *touch = [touches anyObject]; NSLog(@"%@",touch); CGPoint location = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:location]; if(node == mySKSpriteNode) [node runAction:[SKAction fadeOutWithDuration:0]];}
在我的日志中,当我点击屏幕时(不是我有对象的地方),我得到了这个:
2014-02-17 23:18:30.870 BubbleChallenge[48541:70b] Something was touched2014-02-17 23:18:30.875 BubbleChallenge[48541:70b] <UItouch: 0x1130ea530> phase: Began tap count: 1 window: <UIWindow: 0x109c2ab60; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x109c274d0>; layer = <UIWindowLayer: 0x109c26810>> vIEw: <SKVIEw: 0x109c2e5e0; frame = (0 0; 320 568); autoresize = RM+BM; layer = <CAEAGLLayer: 0x109c0e180>> location in window: {147.5,128.5} prevIoUs location in window: {147.5,128.5} location in vIEw: {147.5,128.5} prevIoUs location in vIEw: {147.5,128.5}
当我触摸mySKSpriteNode时,我在日志中什么也得不到,甚至没有“触及的东西”;
知道为什么会这样吗?
我发现的其他问题说答案是设置userInteractionEnabled = YES ….也许代码中有一个特定点我应该设置它?
所有帮助表示赞赏!
解决方法 您是否尝试过设置spritenode的name属性?在mySKSpriteNode的初始化中:
mySKSpriteNode = [[SKSpriteNode alloc] initWithTexture:sometexture];mySKSpriteNode.name = @"thisIsMySprite"; // set the name for your spritemySKSpriteNode.userInteractionEnabled = NO; // userInteractionEnabled should be Disabled
然后:
-(voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UItouch *touch = [touches anyObject]; CGPoint location = [touch locationInNode:self]; SKNode *node = [self nodeAtPoint:location]; if ([node.name isEqualToString:@"thisIsMySprite"]) { NSLog(@"mySKSpriteNode was touched!"); [node runAction:[SKAction fadeOutWithDuration:0]]; }}总结
以上是内存溢出为你收集整理的无法点击SKSpriteNode – 没有触摸检测到的ios全部内容,希望文章能够帮你解决无法点击SKSpriteNode – 没有触摸检测到的ios所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)