Search code examples
c++cocos2d-x

Possible to copy/duplicate a CCLayer?


I'm creating a scene that will have a list of items, like a shop menu. Ideally, I want to create the layout for a single shop item in CocosBuilder. Then, in code, I access that layout and make multiple copies for all my shop items, which can be added to the scene.

Is this possible in cocos2d-x?


Solution

  • if all of items you have are CCSprite, you can use this code for duplicating it:

    CCSprite* copy=CCSprite::spriteWithTexture(source->getTexture());
    

    you can duplicate all sprites in a layer then add them to a new layer.