2011-12-10 11 views
1

私はCCRenderTextureを使って簡単な背景を描こうとしています。CCRenderTextureを使用して背景を作成するには?

IはCCRenderTextureポインタ(HT、幅のピクセルフォーマットを初期化)

は、いくつかの色でcleare作成。

がノードに追加、

=============================ノードラベルを追加しました========================================== =========== 私はそれを実行しているとき、私はそれにラベルをつけた世界のちょうど黒い画面を見ています。

そのテクスチャはどこですか?

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

答えて

0

This CCRenderTexture tutorialは、Cocos2D iPhone用ですが、いくつかのアイデアがあります。一般的な原則は同じです。たとえば、そのレンダリングテクスチャとは別のスプライトを作成し、そのスプライトを子として追加する必要があります。

関連する問題