Tonight, after several attempts to smash the keyboard, I made it. What is it? Let me see if I can explain it clearly.
Aren't we building a main game layer? It has several sub-layers, which are scattered around the main game layer; it can be seen that many points around the middle point;
Now the question is how to establish a connection between these sub-layers, for example, what I'm going to talk about next: every sunflower plant should add a corresponding value to the gold coin when it matures, right, but sunflower elves and gold coins are not on the same layer, how do you realize the operation of gold coins in the layer where the sunflower is located?
Waste a long time, always wrong, wrong is annoying; but at 22:30 I found a solution:
Let's see some of the code: I'll write the complete code tomorrow; I'm afraid I can't write it tonight. How sleepy!
void SunCellLayer::initSunCell(float dt)
{
this->_sunCellSprite = SunCellSprite::create();
this->_sunBatchNode->addChild(this->_sunCellSprite);
CCSize winsize = CCDirector::sharedDirector()->getWinSize();
this->_sunCellSprite->setPosition(ccp(3*winsize.width/4 * rand()/RAND_MAX + 1*winsize.width/5,winsize.height+this->_sunCellSprite->getContentSize().height));
this->SunCellMoveWay();
}
void SunCellLayer::SunCellMoveWay()
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCFiniteTimeAction* sunCellMove1 = CCMoveTo::create(4.0f,ccp(this->_sunCellSprite->getPosition().x,1* winSize.height/4 *rand()/RAND_MAX + 2*winSize.height/5));
CCFiniteTimeAction* sunCellMove2 = CCMoveTo::create(0.5f,ccp(2*winSize.width/7, 8*winSize.height/9));
this->_sunCellSprite->runAction(CCSequence::create(sunCellMove1,sunCellMove2,CCCallFuncN::create(this,callfuncN_selector(SunCellLayer::removeSunCell)),NULL));
}
void SunCellLayer::removeSunCell(CCNode* pSend)
{
CCSprite* sprite = (CCSprite*) pSend;
this->_sunBatchNode->removeChild(sprite,true);
((GameLayer*)this->getParent())->_dollarDisplayLayer->_dollar = ((GameLayer*)this->getParent())->_dollarDisplayLayer->_dollar +25;//Here it is.
}
Let's do that first. Explain it tomorrow.
Reprinted at: https://www.cnblogs.com/riasky/p/3455475.html