I have a level scene in my game in which I am selecting the level. In this scene I am displaying the level selected in a CCLabelTTF. Now I want to pass the value displayed on this label to my main scene. I am doing this as follows:
HelloWorld *hello=[HelloWorld getInstance]; //HelloWorld is main scene
hello.strLevel=[lblLevel string]; //strLevel is NSString to which I am passing the label text
[[CCDirector sharedDirector]replaceScene:[HelloWorld node]];
In my HelloWorld scene I am using singleton to share the value of label used in Level scene.
//HelloWorld.h
@interface HelloWorld : CCColorLayer
{
NSString *strLevel;
}
@property(nonAtomic,retain)NSString *strLevel;
+(HelloWorld*)getInstance;
HelloWorld.mm
@implementation HelloWorld
@synthesize strLevel;
static HelloWorld *instance=nil;
__________________________
//Some code
__________________________
+(HelloWorld*)getInstance
{
if(instance==nil)
{
instance=[HelloWorld new];
}
return instance;
}
However this isn't working.As soon as control reaches
instance=[HelloWorld new];
init() is called. And why not. However when the control reaches back to Level scene at the line where I am passing the value, nothing happens and HelloWorld shows the value null for strLevel.
I know singleton is a better way to pass values than AppDelegate. But I am unable to do so.Can someone correct me?
Thanks