Cocos2D-x 3.0中的基元和子图形Z索引不一致吗? [英] Primitives and sprites Z index in Cocos2D-x 3.0 is not consistent?

查看:71
本文介绍了Cocos2D-x 3.0中的基元和子图形Z索引不一致吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两层.每个层都使用OpenGL这样绘制一个原始图形:

I have two layers. Each layer has a primitive drawing in it with OpenGL like this:

void Layer1::drawPolygon()
{
    glLineWidth(1);
    DrawPrimitives::setDrawColor4B(255,255,255,255);
    DrawPrimitives::setPointSize(1);

    // Anti-Aliased
    glEnable(GL_LINE_SMOOTH);

    // filled poly
    glLineWidth(1);
    Point filledVertices[] = { Point(10,120), Point(50,120), Point(50,170), Point(25,200), Point(10,170) };
    DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) );
}

当我将这些层添加到场景中并设置Z阶1和2时,我看到可以将一个原语放在另一个原语之上,反之亦然-当我交换Z阶值时.当我将sprite插入这些层之一时,奇怪的事情开始了.如果我addChild一个sprite,则sprite不仅位于该层,而且位于该层的图元之上.即使该层具有较小的Z索引,无论如何,其子画面仍位于另一层图元的顶部,而其图元位于另一图元形状的下方(这是预期的).这个可以吗?我应该如何理解?如果我想在所有精灵上绘制图元怎么办?

When I addChild these layers to a scene and set Z orders 1 and 2, I see that I can bring one primitive on top of another and vice versa - when I exchange the Z order values. The strange things start when I addChild a sprite into one of these layers. If I addChild a sprite, then sprite lays on top of the primitive of that layer, and not only that layer. Even if the layer has smaller Z index, anyway its sprite is on top of other layer's primitive, while its primitive is below the other primitive shape - as was expected. Is this OK? How I should understand this? What if I want to draw primitives on top of all sprites?

我可以使用以下命令来操纵其顺序,但不能操纵绘图顺序:

I could manipulate their order, but not drawing order, with the following:

CCDirector::getInstance()->setDepthTest(true);
myLayer->setVertexZ(-1);

但是我不明白为什么Z顺序较小的图层中的精灵比Z顺序较大的图层的图元绘制得晚.换句话说,似乎所有图层中的所有图元都是按照其顺序绘制的,然后对精灵进行相同的操作.

推荐答案

由于在cocos2d-x 3.0上使用了新的多线程渲染器,因此使用基元进行绘制需要使用不同的方法.看看我对此线程的回复:

Due to the new multithreader renderer on cocos2d-x 3.0, drawing with primitives requires a different approach. Take a look at my reply at this thread:

https://stackoverflow.com/a/22724319/1468700

这篇关于Cocos2D-x 3.0中的基元和子图形Z索引不一致吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆