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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:22:16+00:00 2026-06-09T00:22:16+00:00

I have some sprites that I do not know what class to subclass from.

  • 0

I have some sprites that I do not know what class to subclass from. I currently do it with CCLayer because I can keep all the children that I have to add to the sprite in its class, however touch events are detected by all overlapping layers and that might not be so clever. So in layman terms, I want to have a flame thrower for instance where I have to add a flame when I touch it. I do that by just adding the flame within the FlameThrower.h class (which sub classes CCLayer. If I were to subclass CCSprite, I would have to add the flame in my parent’s class which is ineffective as well, right ? So, what is the right approach here ?

  • 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-09T00:22:18+00:00Added an answer on June 9, 2026 at 12:22 am

    You might not need to be subclasssing CCSprite or CCLayer at all.

    This is a fundamental Cocos2d game architecture issue that I wish would be discussed more often.

    For the games that I have created, I use NSObject or CCNode as the base class for creating characters.

    These character controller classes run the logic for the AI of the character, own the physics bodies for the character if it has physics, and control one or more sprites that represent the character.

    If the character controller will not require properties or functionality provided by a CCNode, then I subclass NSObject, which usually is the case for physics based characters.

    User input is usually owned by a HUD, but sometimes you will want to add it directly to specific character in the game world. In that case you might want to subclass a CCLayer to add touch and accelerometer or subclasss a CCNode and register with the touch dispatcher.

    Usually I create the sprites for a character in a separate class that is then created and owned by the character controller.

    The games I create usually have between one and four sprite sheets and I have a GameManager class load these as CCSpriteBatchNodes and into the CCSpriteFrameCache and then when the characters are created via a world building scripting engine I pass a reference to the needed CCSpriteBatchNode to that character so that it can use the batch node to add the characters sprites to it.

    Characters then register with the GameManager or a parant character to be updated, managed, and eventually destroyed and cleaned up.

    For physics based characters there usually isn’t even a need to subclass CCNode (much less a CCLayer or CCSprite) unless you want the physics body to control the behavior of the node directly instead of controlling the sprites that the node or NSObject would own.

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

Sidebar

Related Questions

I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code that will change the background color of a specific label
i have some problems with a Query seem IN dosen't work with Group_concat, that
I know it's not possible to overload operators in as3, and have been using
I have a based image and some sprites on top of the basd image
I have a game object that manages several sprite objects. Each of the sprites
I have a webpage that uses sprites for its navigation link. In IE7 sometimes
How can I have that functionality in my game through which the players can
Currently I am having static reference to all my sprites and loading and initializing

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.