ios - Runtime error when trying to add a node declared in other class -


what i'm trying custom node class, in init creates it's own individual nodes (declared @properties, can access them anywhere. these nodes custom classes found here correct way create button in sprite kit?). if try [self addchild:] these individual nodes in gamescene.m, crash giving runtime error. adding exception breakpoint tells me problem in line showed below, don't understand why. error "trying add nil node parent skscene name (null)", although gave node name. please push me in right direction. i'm absolute beginner ios development, , tried want achieve, no luck.

source code:

directionalpad.h

#import "directionalbutton.h"  @interface directionalpad : skspritenode  @property(nonatomic)directionalbutton *dirbtnleft; @property(nonatomic)directionalbutton *dirbtnright;  @end 

directionalpad.m

    -(void)addbuttons     {         //executed in init method         nsstring *pathtoimageforleftbuttontexture = @"buttondirectionalleft";         nsstring *pathtoimageforrightbuttontexture = @"buttondirectionalright";         self.dirbtnleft = [[directionalbutton alloc]initwithimagenamednormal:pathtoimageforleftbuttontexture selected:pathtoimageforleftbuttontexture]; /*setting size, position, name, zposition*/         self.dirbtnright = [[directionalbutton alloc]initwithimagenamednormal:pathtoimageforrightbuttontexture selected:pathtoimageforrightbuttontexture]; /*same here*/     } 

gamescene.m

#import "directionalbutton.h" #import "directionalpad.h"  @implementation gamescene {     directionalpad *pad; }  //some code omitted...  - (void)createhud {     //executed in didmovetoview:      pad = [[directionalpad alloc] init]; /*problematic line*/         [self addchild:pad.dirbtnleft]; /*end*/     [self addchild:pad.dirbtnright];     [self addchild:pad]; } 

you not show init method directionalpad class. init method explicitly create new directionalbutton objects (with alloc , new)?. if not, creating pad object dirbtnleft , dirbtnright properties both have value nil after create pad. therefore

[self addchild:pad.dirbtnright]; 

will equivalent to

[self addchild:nil]; 

which not want done. runtime error message telling you. name (null) part of message irrelevant in case.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -