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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:52:51+00:00 2026-06-09T17:52:51+00:00

I’m working through the ‘Learning Cocos2d’ book, and I’m stuck on something basic. So,

  • 0

I’m working through the ‘Learning Cocos2d’ book, and I’m stuck on something basic.

So, theres a parent Class: GameplayLayer. In it, there’s an ‘init’ method which creates an instance of the main character in here – ‘Viking’. Viking is a subclass of ‘GameCharacter’, which is a subclass of ‘GameObject’.

        #pragma mark INIT PLAYER
        Viking *viking = [[Viking alloc] 
        initWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache]
        spriteFrameByName:@"viking.png"]];

        [viking setJoystick:leftJoystick];
        [viking setFireButton:fireButton];
        [viking setSecondaryButton:secondaryButton];
        [viking setCollisionLayer:collidableLayer]; // send collision layer to player
        [viking setPosition:ccp(screenSize.width * 0.35f, screenSize.height * 0.14f)];
        [viking setHealth:100];

        [sceneSpriteBatchNode addChild:viking z:1000 tag:kPlayerSpriteTagValue];

Now, Viking has an update method which is called every frame by GameplayLayer. It’s parent class, GameObject also has this update method, which brings up an error message if it is accidentally called – “GameObject update should be overridden’.

So in my code, I’m calling the update method of ‘Viking’ with the following method:

    #pragma mark UPDATE_METHOD
-(void) update:(ccTime)deltaTime
{
    CCArray *listOfGameObjects = 
    [sceneSpriteBatchNode children];
    for (GameObject *tempChar in listOfGameObjects) {
        CCLOG(@"engine found %@",tempChar);
        [tempChar updateStateWithDeltaTime:deltaTime
 andListOfGameObjects:listOfGameObjects];
    }

}

So, this is supposed to call the ‘updateStateWithDeltaTime’ method in Viking. But somehow, it’s calling the parent method in GameObject which says ‘updatestate should be overridden’. How do I override the parent method?

Many thanks,

Carl

  • 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-09T17:52:53+00:00Added an answer on June 9, 2026 at 5:52 pm

    You need to cast tempChar to a Viking.

        for (GameObject *tempChar in listOfGameObjects) 
        {
            [(Viking *) tempChar updateStateWithDeltaTime:deltaTime
     andListOfGameObjects:listOfGameObjects];
        }
    

    Because you’re doing a for loop with fast enumeration of GameObjects, the local variable assumes that all objects are GameObjects. You need to explicitly cast tempChar to a Viking so that the program knows which class to look for the method in.

    As an interesting side note, if GameObject didn’t have the same method as Viking did, you would be getting a warning in XCode telling you it couldn’t find the method you’re asking for (because it needs to know that every object this could be called on has it).

    You might want to check that the object you’re calling this on is the correct class (if you only want to call this on Viking objects). You’d add if ([GameObject isKindOfClass[Viking class]) above your update method call.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.