首页 > 代码库 > cocos2d-x 场景间传值

cocos2d-x 场景间传值

场景A传值到场景B

 

A.cpp

void A::onClick(CCObject * pObject){    // -----------------1.场景切换----------------------    CCScene * scene = B::scene();    B * layer = (B*)(scene->getChildren()->objectAtIndex(0));    layer->value = http://www.mamicode.com/"要传的值";    CCDirector::sharedDirector()->replaceScene(scene );}

B.h

class B: public cocos2d::CCLayer{public:    virtual bool init();    virtual void onEnter();    static CCScene * scene();    CCString value;    CREATE_FUNC(B);};

B.cpp

void B::onEnter(){    CCLayer::onEnter();    CCLog(value.getCString());}

 

cocos2d-x 场景间传值