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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:41:46+00:00 2026-05-30T03:41:46+00:00

In my game, which is using cocos2d, there is going to be many different

  • 0

In my game, which is using cocos2d, there is going to be many different types of enemies, which all look different, and move all in different ways. Also, there is going to be a couple of different gamemodes, which both use the same enemies. As there will be different gamemodes, I decided to make each of my enemies have their own CCSprite class. In those there will be the way that the sprites move, the animation, etc. When one of these sprite is needed in my game, they will be spawned in to the scene. The only thing is, how do I do this? How do I call for one of the sprites to be create on the screen when they are using a class of their own?

If you want to tell me another way than having these sprites having their own classes, that is fine, but keep in mind that I will be having a couple of different gamemodes. If I do the code for the sprites in the CCLayer class of that gamemode, well I will have to write the code twice, which will take time.

Thanks.

  • 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-30T03:41:47+00:00Added an answer on May 30, 2026 at 3:41 am

    You can just subclass CCSprite and override the default initializer initWithTexture:rect:

    example taken from here

    @implementation MySprite
    -(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect
    {
       if( (self=[super initWithTexture:texture rect:rect]))
       {
            // initialize your ivars here
            //ivar1 = xxx;
            //ivar2 = yyy;
            //ivar3 = zzz;
       }
       return self;
    }
    @end
    
    // And to create an instance of MySprite you simply do:
    MySprite *sprite = [MySprite spriteWithFile...];
    
    // or any of the supported CCSprite methods.
    

    you can have a super class say EnemySprite that looks like this

    @interface EnemySprite : CCSprite
    - (void)addToLayer:(CCLayer *)layer;
    - (void)removeFromLayer:(CCLayer *)layer;
    @end
    

    than create a subclass for each type of enemy for example:

    @inteface BigEnemySprite : EnemySprite
    @end
    
    
    @implementation BigEnemySprite
    - (void)addToLayer:(CCLayer *)layer {
        [layer addChild:self];
        // animation code for your big enemy
    }
    - (void)removeFromLayer:(CCLayer *)layer {
        [layer removeChild:self];
        // animation code
    }
    @end
    

    than you can use them like

    EnemySprite *enemy = [BigEnemySprite spriteFromFile:file];
    [enemy addToLayer:self];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a game on iPhone using the Cocos2D API. It's going well.
I'm using a composite design in my current game which works pretty well. All
I'm working on a game for iPad using cocos2d which involves a board filled
I am working on a Facebook game which is developed using Zend framework. Right
I am working on a Facebook game which is developed using Zend framework. Right
I'm writing a game which uses a border layout with a JPanel using BorderLayout.CENTER.
I am starting to develop a facebook game using ASP.NET + Silverlight Which architecture
I recently started game programming on the iPhone using Cocos2d and Box2d. So here's
I just finish my iPhone game using cocos2d. But before I put it on
I'm making a game which is using sound and images. The weirdest thing is

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.