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

  • Home
  • SEARCH
  • 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 8373447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:40:42+00:00 2026-06-09T14:40:42+00:00

I have built a little ipad game and spritesheets and batchnodes are all over

  • 0

I have built a little ipad game and spritesheets and batchnodes are all over the place. However I have no idea how they really work, when to add a sprite sheet, when to add sprites to the spritebatchnode etc. etc. .

This is what I do in the initial screen (main menu):

CCSpriteBatchNode *spriteSheet  = [CCSpriteBatchNode batchNodeWithFile:@"sprites.png"];
screenSize = [CCDirector sharedDirector].winSize;    
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sprites.plist"];
[self addChild:spriteSheet];

In other classes – I always need to use the same batch node -> “sprites.png” – I call

CCSprite *someSprite = [CCSprite spriteWithSpriteFrameName:someSpriteFrameName.png]; 

and add it to self.

[self addChild:someSprite]; // I do not understand why I would add my sprite to the batch node instead of self 

So the situation is the following:

  • I have 1 file called “sprites.png” where all my sprites are on.

    1. Do I make a new batch node whenever I change the scene ? The spriteframecache should stay the same right ?
    2. What would I have to do with the spriteframecache if i had two sprite sheet files ?
    3. When do I add children to the batch node, and why ?

I really don’t seem to grasp the concept entirely. I know approximately why I use it. But I would really appreciate it if somebody could explain everything to me again in layman terms, so I am 100% sure about what I do. Please try to explain it as basic as it gets.

  • Thank you very much –
    Martin
  • 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-09T14:40:44+00:00Added an answer on June 9, 2026 at 2:40 pm
    1. CCSpriteBatchNode is CCNode successor so you have to create separate instance for every scene. You can use several batch nodes on the scene if you have more than one texture file.

      CCSpriteFrameCache is a singleton so it stays the same during application lifetime.

    2. Add both to CCSpriteFrameCache. CCSpriteFrameCache singleton has loadedFilenames_ field (instance of NSMutableSet) which caches all sprite frames for all scenes.

    3. You have to use batch node when you expect large amount of sprites with similar textures. For example you want to generate 100 coins every 2 seconds. If you use usual CCNode and create sprites on it, your application will allocate these 100 CCSprite objects every 2 seconds. CCSpriteBatchNode is targeted for performance and better memory usage. It works like UITableView with reusable cells.

      When you scroll table view with reusable cells, it does not create new cells. When new cell has to be presented on screen table view simply finds cell with same reuse identifier offscreen and replaces it’s content with new content. CCSpriteBatchNode works in the same way. When you try to add new sprite to it, the node tries to find unused sprite offscreen and replaces it’s content.

      Remember that sprites which you add to CCSpriteBatchNode have to use the textures from texture file which was used to create this batch node.

      Following example is based on code from your question:

    CCSpriteBatchNode *batchNode  = [CCSpriteBatchNode batchNodeWithFile:@"sprites.png"];
    screenSize = [CCDirector sharedDirector].winSize;    
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sprites.plist"];
    [self addChild:batchNode];
    CCSprite *someSprite = [CCSprite spriteWithSpriteFrameName:@"someSpriteFrom_sprites.png_.png];
    [batchNode addChild:someSprite]; // add sprite to batch node to get all advantages of it
    

    Here is a good article about CCSpriteBatchNode performance: http://www.learn-cocos2d.com/2011/09/cocos2d-spritebatch-performance-test/

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

Sidebar

Related Questions

I have built a little Web UI for Pidgin(respectively all libpurple based messengers) together
In my little scratch built flex game framework, I have defined a class called
I have built a little web application with several *.js files. I am using
We have a little in-house LMS with courses built in Flash. Scores are updated
Good day. I have little usage of Flash CS4, however i have to build
I have built a variety of little scripts using Ruby's very simple Queue class,
I have built a little static object for saving generic types to Isolated Storage
I built this nifty little weather/clock app as a way of learning to work
I have built little custom web framework on top of Python 3.2 using Cherrypy
I have built a little editor for resource files. So I show the content

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.