cocoa - in objective-c initializing an object and giving it an instance name -
in cocos2d-iphone have cclayer class called gamescene
i want use class class dont know name of instance of gamescene class
i initialized instance of gamescene class follows
-(id) init { if ((self = [super init])) { however not give me name of instance
i read in documentation method called initwithname can used tried not work gives me warning:
in function '-[gamescene init]': warning: 'cclayer' may not respond '-initwithname:' the code tried is
-(id) init { if ((self = [super initwithname:"gamescene"])) { i need 1 instance of class through game cant catch handler of instance can use other classes?
any idea
many thanks
update:
hello
i going update code let know have tried solution dosnot seem work yet
in myappdelegate.h have lines of code:
firstly have defined app delegate share other classes
myappdelegate.h
#define ad (myappdelegate *)[[uiapplication sharedapplication] delegate] and in myappdelegate.m have following code:
gs = [[gamescene alloc] init];//this gamescene sc = [gs scene]; //this calls method -(id)(scene) [[ccdirector shareddirector] runwithscene: sc]; //runwithscene now when tried use gs within other class -for example player.m class-
player.m
gamescene* gs = [ad gs]; //retrieving instance appdelegate [gs updatescorebyamount:5];/calling method "updatescorebyamount" the results , guess happens?
the program runs without errors gs instance seems different 1 run appdelegate since method "updatescorebyamount" not affect scene run runwithscene in appdelegate
any idea?
many have tried help
if understanding correctly, need reference instance of gamescene class? if case, depends how object created. creating instance controller class , like:
gamescene *gamescene = [[gamescene alloc] init]; here, gamescene reference instance need.
Comments
Post a Comment