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

  • Home
  • SEARCH
  • 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 7619067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:33:53+00:00 2026-05-31T03:33:53+00:00

I have 3 classes, The ObjectBody(BodyNode), MainSetupScene(CCLayer), and HudLayer(CCLayer) I’ve setup ObjectBody and HudLayer

  • 0

I have 3 classes, The ObjectBody(BodyNode), MainSetupScene(CCLayer), and HudLayer(CCLayer)

I’ve setup ObjectBody and HudLayer in my MainSetupScene and that’s the requirement for it to work.

What i am trying to do now is to add a method where ObjectBody get the privilege to access HudLayer, So the ObjectBody get to access the method created in HudLayer.

3 important points
-ObjectBody is a BodyNode class.
-The method i am trying to access is -(void) located in HudLayer.
-ObjectBody is a b2Body, it calls up the method in HudLayer when Collision is detected.

I did some researches and i came across this, I’ve tried setting up this code in my ObjectBody

HudLayer *hud = [[hud alloc] init];
[self addChild:hud];
[hud NameOfTheMethod];

However BodyNode class doesn’t accept HudLayer as child.

In short, I am trying to make a BodyNode class trigger a method in a CCLayer class.

  • 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-31T03:33:54+00:00Added an answer on May 31, 2026 at 3:33 am

    Don’t try to introduce “knowledge” to objects just to get messages passed across. What I mean by this is that if you have your ObjectBody, HudLayer and MainSetupScene objects (and I’m going to make some assumptions here) designed such that…

    MainSetupScene “owns” the HudLayer (for this, you probably did in MainSetupScene [self addChild:hudLayer];)

    MainSetupScene “owns” the ObjectBody (again, you probably did in MainSetupScene [self addChild:objectBody];)

    Now, you want objectBody to “communicate” with hudLayer. Don’t try to force the knowledge of the hudlayer to the objectbody or vice versa. Just use delegates.

    So, for example, in your objectBody you might declare the following

    @protocol ObjectBodyDelegate
    -(void)objectBodyStateChanged;
    @end
    

    Now, your mainsetupscene would have it’s definition as

    @interface MainSetupScene : CCScene<ObjectBodyDelegate>
    ...
    

    Now in your ObjectBody class, when you want to send a message to the hud, use the delegate [delegate objectBodyStateChanged];

    Which will be handled by your MainSetupScene. This would then decide to update the HUDLayer by calling the relevant methods and setting appropriate values (which it may get from objectBody).

    In short, the body tells the scene that something has happened to make it change. The scene then knows what needs to be updated to reflect that change. The body shouldn’t know that the hud exists and the hud shouldn’t know the body exists.

    There’s more to implementing the delegates than I put in here, but if you search around you’ll find lots of details of it.

    EDIT AFTER COMMENT
    Your protocol is defined in the interface of one class (class A), but the implementation is written in another class (class B). That’s why it’s called delegation – you delegate the work to another class.

    You will also need to have a delegate defined and set. So, in class A .h you’d have

    @protocol ClassADelegate
    -(void)doSomethingAfterSomethingChanged;
    @end
    
    @interface ClassA {
    id <ClassADelegate> delegate;
    }
    @property (nonatomic, retain) id<ClassADelegate> delegate;
    

    In class A .m implementation, you’d have

    @implementation ClassA {
    @synthesize delegate;
    
    -(void)changeSomething {
    ... Do whatever you need to do ...
    // Now call the delegate
    [delegate doSomethingAfterSomethingChanged];
    }
    

    In class B .h you’d have

    @interface ClassB<ClassADelegate> {
    }
    

    Then in the .m implementation, you’d have

    @implementation ClassB {
    -(id)init {
       .. Do whatever, but when you create your ClassA, set this as delegate ...
       ClassA myClassA = [[ClassA alloc] init];
       myClassA.delegate = self;
    }
    
    -(void)doSomethingAfterSomethingChanged {
    // This gets called by ClassA
    }
    

    There’s lots of better tutorials about delegates that explain it better than this. Hopefully this will make it a bit clearer. You may have used delegates already with UITableView controls and lots of other things in the iOS SDK.

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

Sidebar

Related Questions

I have classes that are named exactly the same across different plug-ins that I
I have classes that are needed in both my web service and my server.
Assume I have classes A1 and A2 and a class B that has elements
I have a couple classes that have nearly identical code. Only a string or
I have classes such as AccountsController, ProductsController etc that all inherit from BaseController. Unity
I often have classes that are mostly just wrappers around some STL container, like
I want to have classes that can mix only specified traits: class Peter extends
If I have classes that need to be shared between my webapp and Tomcat
I have noticed that most PHP-based libraries or frameworks have classes that don't explicitly
In the projects I worked on I have classes that query/update database, like this

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.