I do want to implement my own tile map. (Not using Tiled!)
To move on the map I use a camera and set its position. I also could use “Follow:”.
I am adding all tiles of my game as individual sprites to the scene. (This could be alot, lets say 100*100 = 10000 sprites).
-
Is the engine (or the camera or anything) “deciding” which nodes are visible and only drawing the visible ones or is it drawing everything?
-
If 1. is not handled by the engine: Is there a benefit in grouping sprites together and dynamically adding/removing them (like a chunk system) so that the draw calls will decrease alot?
(e.g. create 10*10 = 100 nodes and add 100 sprites to each node, then removing/or adding only the few nodes (and so its contained sprites) that are actually in the cameras view)
Thanks!
EDIT:
I read about SpriteBatchNode. It this the way to go as it reduces draw calls?
I am used to implement my own draw() method to decide manually which sprites should be drawn.
Sprites are batched automatically in 3.x, technically.
I read that too.
Still is there a performance boost by calling removeChild() over setVisible(false) ?
You will want to manually batch, don’t rely on the automatic batching for that many sprites. Checkout TMXFastTiledMap for guidance on how to build up PrimitiveCommand (or Quad/CustomCommand) for your needs.
Edit: depending on your sorting/depth-buffer needs you may want to batch only rows or some amount of the tiles together and you can also look into culling out off-screen tiles, but you’ll want to either experiment and profile since sometimes culling can decrease performance due to CPU overhead.
If you are targeting higher-end devices you can look into your own rendering tech with 2D texture arrays.
could you send me a link to the docs for TMXFastTiledMap. I havent found anything.
You’d have to look at the source.
I think FastTMXLayer is actually where most of the rendering code exists.
https://github.com/cocos2d/cocos2d-x/blob/7dcee2bcf9246c9345578114ae9e0fe7f8cdd996/cocos/2d/CCFastTMXLayer.cpp .