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 9169709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:54:58+00:00 2026-06-17T15:54:58+00:00

I was reading Learn Cocos2d 2; and stumbled across this problem: in a game

  • 0

I was reading Learn Cocos2d 2; and stumbled across this problem: in a game scene one might have thousands of entities below the scene hierarchy and all these entities might want to talk to the topmost scene object. The author of Learn Cocos2d 2 suggests using a global variable like this

static GameLayer* sharedGameLayer;
+(GameLayer*) sharedGameLayer
{
    NSAssert(sharedGameLayer != nil, @"GameScene instance not yet initialized!");
    return sharedGameLayer;
}

+(id) scene
{
    CCScene *scene = [CCScene node];
    GameLayer *layer = [GameLayer node];
    [scene addChild: layer];
    InputLayer* inputLayer = [InputLayer node];
    [scene addChild:inputLayer z:1 tag:GameSceneLayerTagInput];
    return scene;
}

Personally I think this approach unreliable: imagine a player entity want to know the touch input from another layer in the scene, so it calls sharedGameLayer and assuming it is the parent that it actually resides in it just works on from there. But how can it be so sure? what if this sharedGameLayer is another instance that someone else has allocated? Of course there can only be one scene at a time in cocos2d, and so this approach just might work most of the time without any problem. But from a design point of view, I still find such approach lacking.

I’ve thought about two alternatives:

  1. using the proper (old) delegate approach. Assigning the correct delegate/delegator relationship at each level. However, this means thousands lines of possibly duplicate code and is not neat from my perspective

  2. using NSNotification (or KVO?) to broadcast messages from the children level, and let the parent respond accordingly. But does this mean unnecessary overhead for the system

At this point I’m quite lost, can someone tell me about the general idiom that experienced programmers might use?

  • 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-06-17T15:54:59+00:00Added an answer on June 17, 2026 at 3:54 pm

    You may want to read my “Strategies for accessing other nodes in the hierarchy” guide. Plenty of options to choose from with pros and cons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently reading Learn iPhone and iPad Cocos2D Game Development. i am not able
I am reading through a Learn C book right now and have come across
When i was reading books to learn C# (might be some old Visual Studio
I have started to learn about python and is currently reading through a script
I'm reading Introduction to 3D Game Programming with DirectX 10 to learn some DirectX,
One of the best ways to learn about programming is reading high quality code/projects
I am trying to learn assembly my self, and I have been reading different
I am currently trying to learn Android. Have been reading tutorials and manual for
I am trying to learn JavaScript. After reading this page: What does ':' (colon)
I have been learning and using Objective-C and cocos2d (iOS game-engine) for a couple

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.