Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4320698
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:39:43+00:00 2026-05-21T08:39:43+00:00

I have a level scene in my game in which I am selecting the

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:39:44+00:00Added an answer on May 21, 2026 at 8:39 am

    Use singleton. What should my Objective-C singleton look like? this is a good discussion on the singleton in obj-c. good luck

    [EDIT]

     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]];
    

    The HelloWorld instance that you’re passing to the replaceScene is not the same as
    the HelloWorld *hello you passed the singleton instance to. That’s why there is no strLevel value in it. The strLevel value is placed in your HelloWorld singleton though. Try

    NSLog(@"%@",[[HelloWorld getInstance] strLevel]); //somewhere in the code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a game which have 5 class/level.Each class contain almost same variables.Now i
I have this main scene in a game and I have called the menu
I have two scenes. Scene A is the game scene, where the level variable
I have a cocos2d project with some scenes (home scene, level selection scene, game
I have a scene that is displayed before a level, where the images are
I'm using MySQL. This is table i have Level Programmingtime Clientname projectid 0 128
Is it possible to have microsecond level timestamps in log4j logging? This is on
I have a top level menu in my ShellView and when selecting a sub
I have a class level price variable decalred inside a page, like this: public
I have a level scene that i allow the user to select a level.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.