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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:29:47+00:00 2026-06-05T14:29:47+00:00

I don’t know if this is possible, but I would like to create one

  • 0

I don’t know if this is possible, but I would like to create one big texture atlas and use it on all classes of the application.

Can one CCSpriteBatchNode be used for multiple classes?

Suppose I create this on the main class

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"atlasGeral.plist"];
self.batchNodeGeneral = [CCSpriteBatchNode batchNodeWithFile:@"atlasGeral.png"];
[self addChild:self.batchNodeGeneral];

and I have another class creating CCLayers on the main class, that is initialized, before using CCSpriteBatchNode, like this:

-(id) init 
{

   if( (self=[super init])) {

        self.bg = [CCSprite spriteWithFile: @"cCircularBG.png"];
        [self addChild:self.bg];

        self.dr = [CCSprite spriteWithFile: @"cCircularDR.png"];
        [self addChild:self.dr];      
  }
  return self;  // self is a CCLayer
}

can this be optimized using the self.batchNodeGeneral from the main class? My idea is to replace these two sprites and others with something like [CCSprite spriteWithSpriteFrameName:…

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-06-05T14:29:48+00:00Added an answer on June 5, 2026 at 2:29 pm

    I’m not entirely sure I follow, but I’m pretty sure the answer is yes.

    CCSpriteBatchNode doesn’t have anything to do with classes, it has to do with assets. The important restriction on the use of batch nodes is that every sprite in the batch needs to reference the same texture atlas. So it is perfectly fine to have one batch node for your entire application and have every gameplay class add its own sprites to that batch. This can turn into a practical issue if your texture atlas becomes larger than the maximum texture size on your target hardware (see iOS device specs for details), but if you still want to have global batches and lots of assets it’s not too hard to create a batch pool indexed by texture ID, create one batch node per atlas, and whenever you create a new sprite add it to the appropriate batch.

    Honestly, I feel like the whole batch node thing is a terrible kludge on Cocos2D’s part that could be made almost completely transparent to developers while still retaining its efficiency, but maybe this opinion is not entirely fair since I haven’t dug around in the rendering code to understand their motivations. I guess it would mess with expectations of how depth sorting works, etc., but still I don’t understand why batching objects for render is made the programmer’s responsibility, it should be done by the engine.

    Edit to add possible solution:

    -(id) initWithMainClass:(MainClass*)mc
    {
    
       if( (self=[super init])) {
    
            self.bg = [CCSprite spriteWithSpriteFrameName: @"cCircularBG.png"];
            [mc.batchNodeGeneral addChild:self.bg];
    
            self.dr = [CCSprite spriteWithSpriteFrameName: @"cCircularDR.png"];
            [mc.batchNodeGeneral addChild:self.dr];      
      }
      return self;  // self is a CCLayer
    }
    `
    

    So when you initialize one of the other classes, you pass the main class instance as a parameter so you can access its fields. Or make the main/manager class a singleton or find another architecture suitable to your needs.

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

Sidebar

Related Questions

I don't know if this has been asked before, but what i'd like to
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
I don't know why, but this code worked for me a month ago... maybe
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if anyone can help me with this or if it's even possible.
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know where else to ask, but from one day to the other my
Don't know why this is happening, but after submitting a form via JS (using
Don't know if this is an eclipse specific problem but whenever I declare a

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.