Subclass Layer vs Node

I want a container with bunch of Sprites, any performance differences between subclassing Layer vs Node.

Much thanks for any input.

Maybe store them in a Vector?

Also, don’t subclass Layer. It isn’t really needed.

Are you planning on using this container to manipulate the sprites inside visually (positioning, etc)? If this is just a container, you should manage them differently. If you ARE using the container to manage the drawing of all of its children, then don’t subclass anything, just simply use a node and add them as children. If you find yourself needing something from Layer, then change your container to a Layer.

I try to completely separate the game mechanics from the game graphics code. Coding becomes much easier if you are dealing specifically with one aspect or another, rather than everything together. If you are for example storing game items in an inventory container, you should probably create your own code base for inventory containers, items, and all other code required for managing the IDEA of an inventory system. When its time to draw the inventory on screen, your cocos2d-x code should refer to your underlying game infrastructure and draw itself accordingly.

That being said, the above suggestion of using a Vector is a good one, though, I found it made a lot of sense for me to abstract a type of inventory classes, which uses a vector internally and knows how to manage itself.

1 Like

Awesome great inputs!

I will try out node first base on Nick_E input and having them self manage.

Thanks all!