0

The game I'm designing uses multiple nested CCSprites, so that when the parent sprite moves, rotates, scales, etc. the child sprite does as well, automatically, and so do its grandchildren.

It works great but bogs down very quickly since I haven't implemented batch nodes, currently it's making over 4000 draw calls at once which is obviously not optimal.

However as far as I know the only way to use batch nodes is to make all the sprites a child of the batch node. I thought maybe I could add each parent to the batch node and then add the rest as children of that one but that doesn't work.

Any ideas? I'd like to avoid having to manually calculate the position, rotation, scale, etc of each child sprite every time its parent moves, which at the moment seems to be the only way I can think of to make this work.

James
  • 736
  • 1
  • 5
  • 19
  • why can't the parents be in the batch node? Add their images to the same texture atlas as well. – CodeSmile May 21 '13 at 08:01
  • That sounds like a good idea. I tried adding the parents to the batch node, but I got this error: 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id'. Both the parent and child sprites are using not only the same texture atlas but the exact same png from the sprite sheet. – James May 21 '13 at 16:56
  • Yes, that totally worked! I had just forgotten to change one of the child instantiations from "spriteWithFile:" to "SpriteWithSpriteFrameName:" So exciting to see it work at full speed with only one draw call :-D – James May 22 '13 at 00:53

1 Answers1

0

Looks like you CAN in fact nest children inside a ccsprite and have them be a part of the batch node, as long as the parent is a child of the batch node. When I first tried this I'd simply forgotten to change "spriteWithFile:" to "spriteWithSpriteFrameName:" when I created the children of one of the sprites. Now it works perfetly, all in one batch node, with one draw call. Hooray!

James
  • 736
  • 1
  • 5
  • 19