objective c - Does userInteractionEnabled property work correctly on SpriteKit nodes? -


i have following simple code:

// //  bgmyscene.m //  test1 // //  created andrewshmig on 3/10/14. //  copyright (c) 2014 bleeding games. rights reserved. //  #import "bgmyscene.h"  @implementation bgmyscene  - (id)initwithsize:(cgsize)size {     if (self = [super initwithsize:size]) {         /* setup scene here */          self.backgroundcolor = [skcolor colorwithred:0.15                                                green:0.15                                                 blue:0.3                                                alpha:1.0];  //      first label         sklabelnode *mylabel = [sklabelnode labelnodewithfontnamed:@"chalkduster"]; //        mylabel.userinteractionenabled = yes;         mylabel.text = @"hello, world!";         mylabel.fontsize = 30;         mylabel.position = cgpointmake(cgrectgetmidx(self.frame),                                        cgrectgetmidy(self.frame));         [self addchild:mylabel];  //      second label         sklabelnode *mylabel2 = [sklabelnode labelnodewithfontnamed:@"chalkduster"];         // mylabel2.userinteractionenabled = yes;         mylabel2.text = @"hello, world!";         mylabel2.fontsize = 30;         mylabel2.position = cgpointmake(100, 100);         [self addchild:mylabel2];     }     return self; }  - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [touches anyobject];     cgpoint touchlocation = [touch locationinnode:self];     sknode *touchednode = [self nodeatpoint:touchlocation];      nslog(@"touchlocation x: %f , y: %f", touchlocation.x, touchlocation.y);      if (touchednode != self) {         nslog(@"removed parent.");         [touchednode removefromparent];     } }  - (void)update:(cftimeinterval)currenttime {     /* called before each frame rendered */ }  @end 

what creating 2 sklabelnodes , checks if labels touched, if yes - remove them parent node.

the strange thing when set userinteractionenabled yes sklabelnode won't receive touch event. leaving userinteractionenabled no works fine.

maybe better name property userinteractiondisabled? missing it?

your code working expect would.

as far can see not sklabelnodes receiving touches skscene has -(void)touchesbegan... means if add sklabelnodes , set them .userinteractionenabled = yes soak touches before reach scene, because they're on top of scene.

otherwise should subclass sklabelnode , set userinteractionenabled in custom initialiser. , have touchesbegan in subclass of sklabelnode.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -