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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:03:45+00:00 2026-06-13T11:03:45+00:00

my question is about communicating two directions from one class to its child. I

  • 0

my question is about communicating two directions from one class to its child.

I have a GameLayer CCLayer with a child GameObject CCNode. The GameLayer is a semi-singleton shared layer. I need to import in GameLayer’s header the GameObject.h to be able to init the GameObject. I am now trying to communicate back to the gamelayer and I’m stuck. THe code all works until the questions.

static GameLevel1Layer* sharedGameLayer;

+(GameLevel1Layer*) sharedGameLayer
{
    NSAssert(sharedGameLayer != nil, @"shared game layer not there yet");
    return sharedGameLayer;
}

On init, I init the GameObject

-(id) init
{
    if ((self = [super init]))
    {
        sharedGameLayer = self;

    GameObject1* gameObject1 = [GameObject1 gameObject1];
    fish1.position = CGPointMake(0, 0);
    fish1.tag = kFish1TagValue;
    [self addChild:gameObject1 z:10];
    }
return self;
}

in game object (which is a node but basically inits a ccsprite)

+(id) gameObject1{
    return [[self alloc] initWithFish1Image];
    }

-(id) initWithFish1Image {
    if ((self = [super init])) {

        CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
        [frameCache addSpriteFramesWithFile:@"fish1atlas.plist"];

        sceneSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"fish1atlas.png"]; 
        [self addChild:sceneSpriteBatchNode z:0]; 

        fish1Sprite = [[CCSprite alloc] initWithSpriteFrameName:@"fish1_normal_1.png"];
        fish1Sprite.tag = kFish1SpriteTag;
        fish1Sprite.rotation = -30;
        [self addChild:fish1Sprite];


        }
    return self;
    }

My problem is that from within GameObject I’m trying to send a message to GameLayer1. If I include GameLayer1.h the argument gets circular and I get an undeclared identifier confusion. If I just try:
[GameLayer1 sharedGameLayer] methodImTrying];
It doesnt recgonize and I get an undeclared identifier.

I tried adding:
@class GameLayer1;
and when I send a message to GameLayer it fails that “class message is a forward declaration”.

[self.parent method]; and [super method] both fail.

I thought using a shared layer would allow me to access the parent node without having to import the header for the gamelayer in the gameobject. I know this is a basic question of objective-c, any help would be appreciated.

UPDATE:

If I instead import GameLevel1Layer.h into GameObject’s header and add the @class GameObject to GameLayer, I can call
[GameLevel1Layer sharedGameLayer] method];
i wonder if i’m doing this all quite wrong.

  • 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-13T11:03:46+00:00Added an answer on June 13, 2026 at 11:03 am

    Simplest way to avoid this problem is to use forward declarations.

    In .h file of GameObject1 just declare

     @class GameLevel1Layer 
    

    and in GameObject1.m include GameLevel1Layer.h

    In .h file of GameLevel1Layer just declare

     @class  GameObject1
    

    and in GameLevel1Layer.m include GameObject1.h

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

Sidebar

Related Questions

One question for design about communicating between fragments, why would someone use a bit
I have a question about the Communication between a client and a server. I
Question about subclassing in matlab, under the new class system. I've got class A
Question about GridView sorting in VB.NET: I have a GridView with AutoGenerateColumns = True
one question about PHP Development. I am building up some Form Fields for Calculations.
A question about inheritance in java... class Base { private int val = 10;
This is a two-parter question here. The first is a technical question about how
This is a question about design approach. I have limited COM experience and a
I have a question about communication between activities on implementation program of Android. Here
I have seen the question: Communication between two separate Java desktop applications (answer: JGroups)

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.