用draw画一条直线,怎么总被遮挡。z-order也设置了。

  // add "HelloWorld" splash screen"
    auto sprite = Sprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    // add the sprite as a child to this layer
    this->addChild(sprite, -1);

```
 




void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, bool transformUpdated)
{

    glLineWidth(5.0f);
    DrawPrimitives::drawLine(Point(100, 100), Point(500, 500));
}


```

this->addChild(sprite, -1);这一句中的-1改成100试试.如果不行,可能是场景前后的问题

你设置的显示优先级的问题啊

能说明白点吗?谢谢

下次画图还是用NodeDraw方便些,能画在上面。

是DrawNode,

zorder在设置小一些,比如-129等等,试一下,这个可能和引擎本身的渲染有关系

你解决了么?

以HelloWorld为例。

void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    _customCommand.init(_globalZOrder+1);//你设置的zOrder,_customCommand是CustomCommand成员变量
    _customCommand.func = CC_CALLBACK_0(HelloWorld::onDraw, this, transform, flags);
    renderer->addCommand(&_customCommand);
    
}

void HelloWorld::onDraw(const Mat4 &transform, uint32_t flags)
{
    glLineWidth(5.0f);
    DrawPrimitives::drawLine(Point(100, 100), Point(500, 500));
}

```


 

非常感谢!!!

_customCommand是怎么定义的,你定义在哪里,小白啊?

自带实例中找到例子,谢谢

:12: :12: :12: 我还特意写了是成员变量。。。

你写的是“成员变量”,就因为那"下划线"吗?反正没关系了,我已经找到答案了。谢谢您的热心回复!:2: