Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

some times it takes time to create the sprite structures in the scene, I might need to setup structures inside this sprite to meet requirement, thus I would hope to reuse such structures with the game again and again.

I tried that, remove the child from parent, detach it from parent , clean parent with the sprite. but when I try to add the sprite to another scene, it's just wont pass the assertion that the sprite already have parent

did I miss some step ?

add an example:

I have a sprite A which involves of quite a few steps to construct, so I used it in scene A layer A, and then I want to use it in scene A layer B, scene B layer A1 etc..... generally speaking I don't want to reconstruct the sprte again.

share|improve this question
    
How did you create your Sprites; CCSprite::create(...) or manually new ? –  EmAdpres Jun 22 at 8:53
add comment

1 Answer 1

Do you mean you want to quickly reuse sprite without re-create it?

You may need to consider using ObjectPool to create those sprites ahead of time for certain number of instances you may need, then whenever you need to use it in the game, there will be no time wasted in creation.

Edit: ObjectPool is where it has a whole bunch of objects already created ahead of time. Basically it has 2 managed arrays of objects which are free-array and active-array. At first, you just pre-create those objects to cut the time that would be lost and would hurt user experience if you create them on-the-fly during gameplay, all of those objects sit in free-array. Then whenever you need to use it, you pop it one-by-one from free-array and use in your game. So they will be removed from free-array and added into active-array. After you're done using it, you reset their states and return them back to free-array. It goes like this. Performance is great in magnitude compared to on-the-fly approach.

share|improve this answer
    
can you elaborate ? –  zinking May 26 '13 at 16:08
    
I edited my answer, please take a look again. –  haxpor May 26 '13 at 19:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.