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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:03:24+00:00 2026-05-29T11:03:24+00:00

I have a class Hero, subclassed from CCSpriteBatchNode (cocos2d): @interface Hero : CCSpriteBatchNode {…}

  • 0

I have a class “Hero”, subclassed from CCSpriteBatchNode (cocos2d):

@interface Hero : CCSpriteBatchNode {...}

I’m initing it like this:

Hero *hero;
...
hero = [[Hero alloc] initWithWorld:world];

Here is init method of Hero:

-(id) initWithWorld:(b2World*)world
{
    if (self = [super init])
    {
        ...
    }
    return self;
}

Till this moment all works fine: I can add hero as a child to my layer, and it will be displayed correctly. But then, I’m trying to get some data from hero. I have this method in Hero class:

-(b2Body*) getBody; //in Hero.h

-(b2Body*) getBody  //in Hero.mm
{
    return selfBody;
}

and my application crashes just after calling [hero getBody]; with error:

* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[CCSpriteBatchNode getBody]:
unrecognized selector sent to instance 0x42bde0’

so, he tries to find method getBody in CCSpriteBatchNode class. offcorse, he cant find it there. But WHY he tries to find it there? Why not in Hero class?
P.S. all my classes are *.mm. I need it to support box2d.

EDIT

The ony time I use hero between initing and calling getBody is adding it to CCLayer:

[self addChild:hero z:0 tag:kTagParentNode]; //self - CCLayer subclass

getBody is called from tick method:

[self schedule:@selector(tick:)];

...

-(void)tick:(float)dt 
{
    CGPoint scaledVelocity = ccpMult(leftJoystick.velocity, 480.0f);
    if (scaledVelocity.y > CGPointZero.y)
    {

        [objectControls jump:[hero getBody]];

    }
    if (scaledVelocity.x > CGPointZero.x) 
    {
    }
}
  • 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-29T11:03:25+00:00Added an answer on May 29, 2026 at 11:03 am

    While it’s hard to tell what’s causing the issue without seeing much code, I advise you to rethink your architecture.

    A CCSpriteBatchNode is an object that’s used by the cocos2d engine to render batched sprites. Is your Hero really such an object? I don’t think so. The Hero should be a class on it’s own and have a has one relation to a CCSpriteBatchNode and a b2Body.

    Why? There are several reasons for this. First and foremost it’s going to decouple your Hero implementation from the interface imposed by cocos2d. If the creators of cocos2d decide to change some implementation details, your class might no longer work if it inherits from a CCNode. Also think about encapsulation: Does a visual component really have to know about player logic?

    If you split up your architecture you’re going to make your code better readable, easier to maintain and also easier to port to another platform if that’s ever going to happen. For a similar post, see this question on gamedev.SE.

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

Sidebar

Related Questions

I have a model like this class Canvas include Mongoid::Document field :name referenced_in :hero
I have made an interface called IHero i implement in my hero.as3 class. the
I have this class called Hero that has the following attributes. String is for
I have class A: public class ClassA<T> Class B derives from A: public class
I want a attribute in my Hero class to have a Portrait attribute for
Have a class Hero. Sometimes I need a deep copy (when all members are
So, I'm trying to inherit a class from another. I have the base class
I have class method that returns a list of employees that I can iterate
I have: class MyClass extends MyClass2 implements Serializable { //... } In MyClass2 is
I have class with internal property: internal virtual StateEnum EnrolmentState { get { ..getter

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.