void MainHomeLayer::updateWaterFall(float dt)
{
static float offset = 0;
if(NULL != _waterFall)
{
_waterFall->removeFromParentAndCleanup(true);
}
CCSprite* background = (CCSprite*)this->getChildByTag(eMainHomeLayer_Background);
CCSprite * waterFall = CCSprite::create("img/mainHome/waterfall.png");
CCTexture2DPixelFormat pixelFormat = waterFall->getTexture()->getPixelFormat();
if(kTexture2DPixelFormat_RGBA8888 == pixelFormat ||
kTexture2DPixelFormat_RGB5A1 == pixelFormat ||
kTexture2DPixelFormat_RGBA4444 == pixelFormat)
{
float scaleX = background->getScaleX();
float scaleY = background->getScaleY();
///Render Texture Begin
CCSize textrueSize = CCSizeMake(waterFall->getContentSize().width * scaleX,waterFall->getContentSize().height * scaleY);
CCRenderTexture* renderTexture = CCRenderTexture::create(textrueSize.width, textrueSize.height, kTexture2DPixelFormat_RGBA8888);
renderTexture->begin();
ccBlendFunc blendFunc1 = {GL_ONE,GL_ONE_MINUS_SRC_ALPHA};
waterFall->setBlendFunc(blendFunc1);
waterFall->setOpacity(30);
waterFall->setPosition(CCPointMake(textrueSize.width * 0.5, textrueSize.height * 0.5));
waterFall->setScaleX(scaleX);
waterFall->setScaleY(scaleY);
waterFall->visit();
ccBlendFunc blendFunc = {GL_DST_ALPHA,GL_ONE_MINUS_DST_ALPHA};
ccTexParams tp = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
float PIXRIS_PRR_SECOND_WATER = (CCRANDOM_0_1() * 20 + 20) * scaleY;
CCSprite * water = CCSprite::create("img/mainHome/Water02.jpg");
water->setBlendFunc(blendFunc);
water->setScaleX(scaleX);
water->setScaleY(scaleY);
water->getTexture()->setTexParameters(&tp);
water->setTextureRect(CCRectMake(0, -offset, water->getContentSize().width, water->getContentSize().height));
water->setPosition(CCPointMake(textrueSize.width * 0.5, textrueSize.height * 0.5));
water->visit();
renderTexture->end();
///Render Texture End
this->setWaterFall(renderTexture->getSprite());
this->getWaterFall()->removeFromParentAndCleanup(true);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
this->getWaterFall()->setPosition(CCPointMake(winSize.width * 0.87, winSize.height * 0.8));
this->addChild(this->getWaterFall(),100);
offset += PIXRIS_PRR_SECOND_WATER * dt;
}
}
原文链接:https://blog.csdn.net/zhenyu5211314/article/details/78357156
沒有留言:
張貼留言