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

The Archive Base Latest Questions

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

I am trying to extend a LHSprite from LevelHelper so I can add different

  • 0

I am trying to extend a LHSprite from LevelHelper so I can add different behavior to different elements.

Ok, so far so good, but what do you want?

Basically imagine a set of characters that have different movements. I want to be able to define a class Character that extends LHSprite and defines a move method. All characters should extend this Character class and define their own movement. This way I can add elements to the map and I can treat them (in terms of movement) in the same way.

Ok, I understood that, but what have you done?

So far I have followed this link about custom LHSprites but I am facing a problem:
The first difference from my case to that one is that I don’t add my elements using the LevelHelper (at least the ones I am trying to extend). I add my elements in code because I want a random number of those elements in a random position.

So I have made this init method that creates a cop (that extends Character and Character extends LHSprite). This method actually looks more to “add to loader” method but whatever:

- (id) initInLoader:(LevelHelperLoader *) loader andNumber: (int) i 
                                                     atPos: (CGPoint) pos{
    self = (Cop *) [ loader createBatchSpriteWithName:@"cop_01" 
                            fromSheet:@"copSheet" fromSHFile:@"enemies" ];

    _uniqueName = [ NSString stringWithFormat:@"Cop_%d", i + 1 ];
    [ self setUniqueName: _uniqueName];

    [ self prepareAnimationNamed:@"cop" fromSHScene:@"enemies" ];
    [ self setAnimationDelayPerUnit: 1.0f/70.0f ];

    self.position = pos;

    [ self playAnimation ];
}

So far so good. I can see my cop standing and animated. However, when I try to call the move method (or any other method) it gives me an unrecognized selector crash.

I believe this error happens because of the cast to (Cop *) but I don’t know how to surpass this.

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

    I found out that I needed to add a tag to the level helper. However, this tag wasn’t updating in the source files so I had to add it manually in the LevelHelperLoader.h, at the enum LevelHelper_TAG.

    Then I had to register that tag when I initialize the LevelHelper

     [[LHCustomSpriteMgr sharedInstance] registerCustomSpriteClass:[Cop class] 
                                                            forTag:COP_TAG];
    

    And I had to pass that tag when I get that element from the loader:

    self = (GlowWorm *) [ loader createBatchSpriteWithName:@"cop_01" 
                                                 fromSheet:@"copSheet" 
                                                fromSHFile:@"enemies" 
                                                       tag: COP_TAG];
    

    EDIT

    To answer the user that made a new answer with a problem

    Don’t forget to tell about the new class to LevelHelper before you initialize LevelHelper. You can do that with this line:

    [[LHCustomSpriteMgr sharedInstance] registerCustomSpriteClass:[Cop class] 
                                                           forTag: COP_TAG ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extend a form and add an upload file field from within
I'm trying to extend all dom elements so i can get and remove their
So I am trying extend the base Application class and add member variables to
I'm trying to extend JButton with Clojure, but I ran into a problem when
I'm trying to extend the SPL ArrayObject but I've hit a little snag. Using
I'm trying to extend the FOSUserBundle so that I can handle two (or even
I'm trying to extend the validation class with my own function but it seems
I trying to extend ConuntDownTimer to add the methods pause and resume in this
I'm trying to extend the DropDownList control to simply add one extra property. Code
I'm trying to extend my webapp with IronPython, which is working wonderfully so far,

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.