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;
}