objective c - Accessing properties of a spritebuilder object outside of its class in Xcode? -
i'm confused on how spritebuilder links in xcode.
i'm using ccbloader "initialize"(?) custom classes have created in spritebuilder, cannot access properties have defined.
in spritebuilder, have ccnode called contentpane has these nested ccnodes called _rockpath1 , _rockpath2, both of contain .png file looks rocks.
_rockpath1 , _rockpath2 both owner variables.
here contentpane looks like: header file:
@interface contentpane : ccnode @property (nonatomic, assign) ccnode * _rockpath1; @property (nonatomic, assign) ccnode * _rockpath2; @end
the .m file:
@implementation contentpane{ } - (id)init { self = [super init]; if (self) { cclog(@"contentpane created"); } return self; } @end
and here initialize contentpane inside file called gameplay.m:
- (void)didloadfromccb { ccnode* pane = [ccbreader load: @"contentpane"]; [self addchild:pane]; //here try access property _rockpath1 pane._rockpath1.position = ccp(50,50); }
it gives me error "property _rockpath1 not found on object of type ccnode"
this because far compiler knows, pane
ccnode
object, , ccnode
not have property _rockpath1
.
you need explicitly declare pane
type expect be, in case contentpane
, , cast object returned +[ccbreader load:]
type:
- (void)didloadfromccb { contentpane *pane = (contentpane *)[ccbreader load: @"contentpane"]; [self addchild:pane]; pane._rockpath1.position = ccp(50,50); }
Comments
Post a Comment