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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:37:47+00:00 2026-05-30T04:37:47+00:00

My question is related to how the use of CCSpriteBatchNode works… When you initialize

  • 0

My question is related to how the use of CCSpriteBatchNode works… When you initialize the CCSpriteBatchNode with a file, let’s say:

CCSpriteBatchNode *spriteBatch;
spriteBatch = [CCSpriteBatchNode batchNodeWithFile:@"file.pvr.ccz"];
[self addChild:spriteBatch];

And then, here is my doubt… Why do you need to add each sprite that you will use to the CCSpriteBatchNode if these are supposed to be loaded when you call batchNodeWithFile?

Here is the code where you add each sprite:

NSArray *images = [NSArray arrayWithObjects:@"sprite1.jpg", @"sprite2.jpg", @"sprite3.jpg", @"sprite4.jpg", @"sprite5.jpg", @"sprite6.jpg", nil];       
for(int i = 0; i < images.count; ++i) {
    NSString *image = [images objectAtIndex:i];
    float offsetFraction = ((float)(i+1))/(images.count+1);        
    CGPoint spriteOffset = ccp(winSize.width*offsetFraction, winSize.height/2);
    CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:image];
    sprite.position = spriteOffset;
    [spriteBatch addChild:sprite]; //Here is what I mean... Why to do this? Isn't that supposed that they are already loaded in the CCSpriteBatchNode?
}

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-30T04:37:48+00:00Added an answer on May 30, 2026 at 4:37 am

    That’s for optimization. basically when you add a CCSprite to a layer involves an OpenGL call to draw the item (in fact they are 7 i think), so if you have 100 sprites, 100 calls are done. If you add them to a BatchNode it takes only one call to draw all their children’s.

    Check the docs:

    CCSpriteBatchNode is like a batch node: if it contains children, it
    will draw them in 1 single OpenGL call (often known as “batch draw”).

    A CCSpriteBatchNode can reference one and only one texture (one image
    file, one texture atlas). Only the CCSprites that are contained in
    that texture can be added to the CCSpriteBatchNode. All CCSprites
    added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call. If
    the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES
    draw call will be needed for each one, which is less efficient.

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

Sidebar

Related Questions

I found this related question: How do I use composition with inheritance? I would
This is related to a question I asked here: Thread Locking in Ruby (use
See this related question on more generic use of the Boost Random library. My
I've a question related to Doctrine 2 and Zend Framework. If you use Zend
This question is related to this one. I need to use the winmm function
I recently faced an interview question related to LINQ. What is the use of
I have a question related to Commerce Server related to products basket. Let's assume
This question is related to performance. If I use a selector like the following
My question is related to SwingUtilities.invokeLater . When should I use it? Do I
Question related to PHP memory-handling from someone not yet very experienced in PHP: If

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.