0

我不能用 DrawNode 和 RenderTexture 画一条简单的线或一个点。

这是我如何实现的:

AppDelegate.cpp

auto scene = Scene::create();
auto layer = BackgroundLayer::create();
scene->addChild(layer);

// run
director->runWithScene(scene);

背景层.cpp

bool BackgroundLayer::init()
{
    if ( !LayerColor::initWithColor(Color4B::WHITE) )
    {
        return false;
    }
    auto renderTexture = RenderTexture::create(300, 200);
    renderTexture->beginWithClear(0, 0, 0, 1); // black
    auto drawPrimitive = DrawNode::create();
    drawPrimitive->retain();
    drawPrimitive->drawDot(Point(250, 250), 20, Color4F::RED);
    drawPrimitive->visit();
    renderTexture->end();
    renderTexture->retain();
    renderTexture->setPosition(this->getContentSize()/2);
    this->addChild(renderTexture, 10000);
}

我用 DrawNode 尝试了一些复杂的形状,但结果只是一个黑色的矩形停留在屏幕的中心。

我用cocos2d-x v3.6 & VS2013.

4

1 回答 1

0
auto renderTexture = RenderTexture::create(50, 50);
renderTexture->beginWithClear(0, 0, 0, 1); // black
auto drawPrimitive = DrawNode::create();
drawPrimitive->retain();
drawPrimitive->drawDot(Point(10, 10), 2, Color4F::RED);
drawPrimitive->visit();
renderTexture->end();
renderTexture->retain();
renderTexture->setPosition(SCREENSIZE.width/2,SCREENSIZE.height/2);
this->addChild(renderTexture, 10000);

试试这个,它会在纹理上创建红点

于 2016-06-08T12:42:12.467 回答