场景A传值到场景B
A.cpp
void A::onClick(CCObject * pObject) { // -----------------1.场景切换---------------------- CCScene * scene = B::scene(); B * layer = (B*)(scene->getChildren()->objectAtIndex(0)); layer->value = "要传的值"; 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()); }