1
我想使用CCRenderTexture繪製一個簡單的背景。如何使用CCRenderTexture創建背景?
我創建了一個CCRenderTexture指針
一些顏色cleare它(與寬度,HT,像素格式初始化)。
加到節點,
添加標籤到節點
============================= ================================================== =========== 當我運行它時,我看到黑色屏幕上帶有hello world標籤。
那麼紋理在哪裏?
bool HelloWorld::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayer::init());
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// 2. Add a label shows "Hello World".
// Create a label and initialize with string "Hello World".
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 64);
CC_BREAK_IF(! pLabel);
// Get window size and place the label upper.
CCSize size = CCDirector::sharedDirector()->getWinSize();
pLabel->setPosition(ccp(size.width/2, size.height - 20));
// Add the label to HelloWorld layer as a child layer.
this->addChild(pLabel, 1);
CCRenderTexture *rt = CCRenderTexture::renderTextureWithWidthAndHeight(120, 120, kCCTexture2DPixelFormat_RGBA4444);
rt->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1());
rt->setPosition(ccp(size.width/3, size.height/3));
this->addChild(rt, 0);
bRet = true;
} while (0);
return bRet;
}