【问题标题】:Cocos2d-x v3: ClippingNode not working on RenderTextureCocos2d-x v3:ClippingNode 在 RenderTexture 上不起作用
【发布时间】:2014-09-12 02:23:06
【问题描述】:

如果 ClippingNode 被渲染到 RenderTexture 而不是被添加为子节点(或者在我的情况下添加到本身渲染到 RenderTexture 的容器中),则效果会被破坏:

精灵没有被遮盖(模板没有效果),屏幕的所有其余部分都用白色填充(在 ClippingNode 被添加到所有其他图层之上的情况下)。

(在ios和win32上测试)

auto stencil = DrawNode::create();
static Point triangle[3];
triangle[0] = Point(-40, -40);
triangle[1] = Point(40, -40);
triangle[2] = Point(0, 40);
static Color4F green(0, 1, 0, 1);
stencil->drawPolygon(triangle, 3, green, 0, green);

auto clipper = ClippingNode::create();
clipper->setAnchorPoint(Point(0.5, 0.5));
clipper->setPosition( Point(100, 100) );
clipper->setStencil(stencil);
clipper->setInverted(true);

// containerAddedAsChild->addChild(clipper, 20);      // this works fine
containerRenderedToTexture->addChild(clipper, 20);    // this breaks 

auto img = Sprite::create("test_sprite.png");
img->setAnchorPoint(Point(0.5, 0.5));
clipper->addChild(img);

如何让 ClippingNode 在 RenderTexture 上工作并获得预期结果(将 ClippingNode 添加为子节点而不是使用 RenderTexture 时获得的结果)?谢谢。

【问题讨论】:

  • 但是你的问题是什么?
  • 在我的帖子中添加了一个问题。

标签: c++ cocos2d-x cocos2d-x-3.0


【解决方案1】:

我不确定这是否正是您所要求的,但您可以通过确保设置深度模板选项让 ClippingNodes 正确渲染到您的 RenderTexture 上。

在 Cocos2d-x 3.x 中是这样的:

RenderTexture* renderTexture = RenderTexture::create(paddedSize.width, paddedSize.height,
    Texture2D::PixelFormat::RGBA8888,
    GL_DEPTH24_STENCIL8_OES); // configure for clipping node

renderTexture->beginWithClear(0, 0, 0, 0, 1.0f);
clippingNode->Node::visit();
renderTexture->end();

在 Cocos2d-iPhone / Swift 3.x 中它看起来像这样:

CCRenderTexture *renderTexture = [CCRenderTexture renderTextureWithWidth:paddedSize.width height:paddedSize.height
    pixelFormat:CCTexturePixelFormat_RGBA8888
    depthStencilFormat:GL_DEPTH24_STENCIL8_OES];
[renderTexture beginWithClear:0.0f g:0.0f b:0.0f a:0.0f depth:1.0f];
[clippingNode visit];
[renderTexture end];

【讨论】:

  • 我正在尝试让它自己工作,其中剪辑节点在子精灵上工作正常,但如果我想将其渲染为纹理,请从剪辑节点调用 Node::visit() 或它里面的精灵不做任何事情。就像它在渲染纹理上不可见一样。我正在使用 CC_GL_DEPTH24_STENCIL8 创建 renderTexture,但这似乎是同一件事的宏
  • 没关系,问题是我在end() 调用之后隐藏了精灵,并且问题以及 RT 的大小太小,因为精灵的位置将其从屏幕上移开.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多