My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 1148: Extended batchnode class
3 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----


Sign in to add a comment
 
Reported by itlbusin...@gmail.com, Mar 26, 2011
This is a extended CCSpriteBatchNode class that allows you to insert particles and sprites from another texture, and will reorder them correctly. It's based on @araker's drawNumberOfQuads method:
http://www.cocos2d-iphone.org/forum/topic/14389

So either you use his method or use last patch from Riq:
https://github.com/cocos2d/cocos2d-iphone/commit/aad266acd2b9854a8a2722244147d57368b89d79
MySpriteBatchNode.h
463 bytes   View   Download
MySpriteBatchNode.m
9.0 KB   View   Download
Mar 26, 2011
Project Member #1 ricardoq...@gmail.com
(No comment was entered for this change.)
Labels: -Type-Defect Type-Enhancement
Mar 26, 2011
Project Member #2 manu.valladolid
A lot of ccArrayInsertObjectAtIndex(_ranges, [NSNumber], r++);

Looks like a very inefficient code.
Mar 27, 2011
#3 itlbusin...@gmail.com
Thanks manu, I was going to change to ccCArrayAppendValueWithResize instead, so to use this instead:

ccCArrayAppendValueWithResize(_ranges, [NSNumber]);

But fist try gave me a EXC_BAD_ACCESS. Didn't have time yet to see why.

But as it is right now, I can get 30fps on a iPod 1G  with 100 sprites (mixed of batchnode sprites, external sprites, and particles) in worst case scenario (changing zorder all of them randomly every frame), do you think that's very inefficient code?

See the post here:

http://www.cocos2d-iphone.org/forum/topic/14747/page/2

Mar 27, 2011
#5 itlbusin...@gmail.com
Replaced ccCArrayAppendValueWithResize with ccCArrayAppendValueWithResize, attached new update.
MySpriteBatchNode.m
9.0 KB   View   Download
Mar 27, 2011
Project Member #6 manu.valladolid
:) You didn't understand me.
I think you should implement a c array like:

@interface
int * _ranges;
NSUInteger capacity_;
NSUInteger count_;

@implementation

init
{
capacity_ = 100;
count_ = 0;
_ranges = malloc(sizeof(int) * capacity_);
}

add
{
_ranges[count_] = __NUMBER__;
count_++;
}

dealloc
{
free(_ranges);
}
Mar 27, 2011
#7 itlbusin...@gmail.com
Thanks Manu. I did base my code on what the original class uses, the main children array on CCNode is also a CCArray, even the reordering is based on same code, so I didn't think there was a need to use something different, but thanks for your suggestion, will have a play. Also note the cost to generate the ranges is low. I just want to make clear that the code is not "very inefficient", that's all I understood from your post. The performance of the class is very similar if not the same than the original CCSpriteBatchNode.
Anyway, thanks! your input is really appreciated, you are doing a great job!
Mar 27, 2011
#8 itlbusin...@gmail.com
But yeah I undertand even a CCArray is not the best option for a simple integer array, I never say my code was perfect! So will try your suggestion later tonight. 
Mar 27, 2011
#9 itlbusin...@gmail.com
Correction: the performance is NOT the same than the original CCSpriteBatchNode, that was a wrong assumption, since we have to split the batchnode and draw in batches, is not possible to match same performance obviously! But I guess is a reasonable price to pay. Anyway will be working on improving as much as I can, thanks you guys for suggestions.
Mar 27, 2011
#10 itlbusin...@gmail.com
Implemented a simple c array for the ranges, thanks to Manu suggestion, got some performance improvements, yeah! But I'm not an expert on c so I'm not sure what I did is ideal, specially the way I reuse the array, anyway, open to suggestions! Obviously we will never match the performance of a single CCSpriteBatchnode since we need to split the openGL calls, but my testing with the worst case scenario (where all nodes change randomly zorder on each frame) and with 100 nodes mixed of children and foreigners, still gets about 40/50 fps on an old iPod 1G, not bad!!
MySpriteBatchNode.h
675 bytes   View   Download
MySpriteBatchNode.m
9.0 KB   View   Download
Mar 27, 2011
#11 itlbusin...@gmail.com
Last performance test (40/50fps) was without particles, whilst the previous performance test without the c array (30fps) was with 5 particles. If I add 5 particles to the foreigners array with the new code, I get the 35/40fps, still a improvement. But since we are testing 100 nodes on a worst case scenario, and probably splitting the batchnode in about 50 batch calls, I still think is a good performance.
Apr 4, 2011
#13 itlbusin...@gmail.com
Overwrote the removeChild to also remove properly the foreigners. Also changed class name.
ExtendedSpriteBatchNode.h
681 bytes   View   Download
ExtendedSpriteBatchNode.m
10.5 KB   View   Download
May 17, 2011
Project Member #14 ricardoq...@gmail.com
(No comment was entered for this change.)
Labels: Component-Sprites
Apr 24, 2012
#15 agentr...@gmail.com
I have a question, if you use the ExtendedSpriteBatchNode, but only add regular batch node sprites, will performance be the same as a regular CCSpriteBatchNode?

I plan to use this class to implement a layer which mainly has regular batch nodes, but only occasionally adds an intercalated explosion sprite.

If I add an explosion, that is removed upon animation termination, will performance be back to what it was before adding the foreign sprites, or does it gets permanently degraded (because of the ranges keeping separated)?
Apr 24, 2012
#16 itlbusin...@gmail.com
Once removed the batchnode performance goes back to normal, yes.
Jan 26, 2013
#17 reynolds...@gmail.com
When attempting to compile, unable to find the sprite property "MutatedIndex" - what is this supposed to be?
Jan 27, 2013
#18 itlbusin...@gmail.com
Are you using cocos2d v1 or v2? Cos this extension only works on v1.
Sign in to add a comment

Powered by Google Project Hosting