Keeping the current CCSprite to another scenes

23 views Asked by At

I'm a beginner of using cocos2d-x.
My problem is I dun know how to keep the CCSprite to another scenes.

The details of my case:

  1. I've made a class"Scene01"includes 5 characters CCSprite with attributes, each of them class name like C1,C2...C5.

  2. I've made a "Draw" button at class"Scene02"to draw out 1 of them randomly. I put this action at "CCTouchesBegan"...the character draw setting as below:

    if      (probability >0 && probability <=20) {result = C1::create();}
    
    else if (probability >20 && probability <=40){result = C2::create();}
    
    ...until C5::create();
    
  3. I use "this->addChild(result);" display on "Scene02" at "CCTouchesBegan".

But I don't know how to keep the generated "result(CCSprite)" to the new scene class"Scene03". Is there any better way(s) to simplify my case or any method(s) can help me to complete it?

1

There are 1 answers

0
George On

You could try the following: retain the Sprite, remove it from Scene02 (keeping it on the heap) and then add it to the Scene03.

//(Scene02)

result->retain();
result->removeFromParent();

..

//(Scene03)

this->addChild(result);
result->release();