What is the alternative of SpriteBatchNode in Cocos Creator?

Hi i have this scene that uses a sprite sheet and tile it as a map…
before in cocos2d-js i am using SpriteBatchNode to optimize my map and it works 101%…
but in cocos creator there is no concept of SpriteBatchNode… And now i am using SpriteFrame and just cloning it for each of my tile… sadly my fps drops 50% how can i fixed this?
can we still use SpriteBatchNode in cocos creator?
@stevetranby do you know a way? thanks

1 Like

You’ll actually want to use SpriteBatchNode still even if cocos creator doesn’t support it (or the equivalent of TriangleCommand in -js like in the latest c++ tile renderer FastTMX).

I’m not sure how you’re trying to do it now, but you might have to create an empty node in cocos creator where the tile map will go and then add the tile map in code at run-time using the SpriteBatchNode version. An alternative would be to use the TileMap node or component so it displays in creator and then replace during init (might take longer loading, but should render with old 2x+ performance).

You shouldn’t have to force everything through the cocos creator interface or system if something isn’t working correctly. Maybe in the future the TiledMap node will be as performant as you need it.

That said maybe @slackmoehrle knows someone who can help with letting you know whether cocos creator can handle this since I don’t really use creator much yet.

@nantas2 can you take a look at this thread and give some ideas?

well the only reason that i am making my own tmx parser is that cocos creator’s tiled map does not fully support object layer…
if cocos creator will support object layer then i dont even have to bother you guys… sorry :smiley:

You should also be able to look into creating your own component plugin. I believe this is what the cocos team would do in the future for specific object types like this.

yeah probably i will,
and as for now this SpriteBatchNode is my issue

I found the solution…
but i think it needs a little change.
i dig in to the Cocos Creator api and i saw that we can use SpriteBatchNode but this SpriteBatchNode is different. It extends CCSGNode, adding this SpriteBatchNode directly to the component.node doesnt seem to work…

var batchNode = new cc.SpriteBatchNode(textureAtlas);
this.node.addChild(batchNode);// does not work

so i search the api again and i found out that each instance of cc.Node has a property _sgNode. Since SpriteBatchNode extends CCSGNode so i try :

 this.node._sgNode = batchNode;// still doesnt work

then i tried :

var node = new cc.Node("new node");
node._sgNode = batchNode;   
this.node.addChild(node); // it works

now my frame rate pumps up at 100% and my batching drop at 1(before was 800)

Btw i create a instance of a Sprite using

var sprite = new _ccsg.Sprite();
sprite.initWithTexture(batchNode.texture, rectForGID(gid), false);
sprite.batchNode = batchNode;
batchNode.addChild(sprite);

Now my question is… Is this the right way of using SpriteBatchNode? or do you guys recommend a better way…
is it fine for us that we are using these core classes by our selves?.. thanks :smile:

1 Like

It’s not recommended to use SGNodes (scene graph nodes) directly, but you have very well accomplished your target. You haven’t talked about what’s the problem of our parser, if you can tell us more we can try to fix it or you can probably send a PR to our engine repo : https://github.com/cocos-creator/engine/ , we really appreciate that.

Now to the batching problem, I have recently implemented auto batching in Cocos2d-html5 v3.11, the solution will also be merged into Cocos Creator very soon, then you wouldn’t need to use SpriteBatchNode.

my issue about the Cocos Creator’s tmx parser is that it does not support Object Layer where i can also put tiles. In TiledMap Editor we make an Object Layer[] and use Insert Tile[] on it to place a tile… but in Cocos Creator's parser it wont show up even though its on the tmx data…
We need this because our game has a City Map(Isometric) that has dynamic size of tiles… like stones,trees,bushes and houses… which im guessing will be added to a ObjectLayer. It would be really helpful if you guys make this kind of support. Its hard to explain sorry for my bad english i hope you get my idea :blush:

Before i was pushed to make our own parser and manage to do the thing but i cannot accurately position the tiles in the ObjectLayer… its off about some small amount pixels…

I hope you consider this @pandamicro… I am sure every body would be happy about it :smiley:

Hi, would love to know if this is now merged into Cocos Creator. Is it released or can we go get the engine on the git to try it before release ?

1 Like

Now to the batching problem, I have recently implemented auto batching in Cocos2d-html5 v3.11, the solution will also be merged into Cocos Creator very soon, then you wouldn’t need to use SpriteBatchNode

Hi, we would also very much like to know the status of this. At the moment we don’t do any batching, so this would probably give us a huge performance boost.

Hi, all,

SpriteBatchNode won’t be added to creator, but don’t worry, auto batching is coming with v1.2, it is already implemented in Cocos2d-html5, I’m porting the implementation to creator recently.

Besides, Tilemap renderer will be reimplemented to be more flexible, will support adding sprite with different texture into the layer.

3 Likes

This sounds great pandamicro, do you know approximately when 1.2 will be out?

1 Like

Do you know if auto batching apply to SkeletonNode ? Or we need to build up our own SkeletonBatchNode

@coindrop v1.2 will be out in July

@muribundi If your SkeletonNode is based on Sprite, then it will work. Auto batching only cares about what render command is sending to the renderer. If you don’t implement your own render command and use Sprite directly, then it should work. If you build your own render command then you need to adopt a function called uploadData to upload the vertex position, color, uv buffer to the global buffer.

1 Like