我正在尝试使用 CCRenderTexture 绘制一个简单的背景。
我创建了一个 CCRenderTexture 指针(使用宽度、ht、像素格式初始化)
用一些颜色清除它。
添加到节点,
为节点添加标签
==================================================== ========================================= 当我运行它时,我看到的只是黑屏,上面有你好世界的标签。
那么纹理在哪里呢?
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;
}