简体   繁体   中英

Keeping the current CCSprite to another scenes

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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM