libgdx ScissorStack not working as expected(libgdx ScissorStack 未按预期工作)
问题描述
我正在尝试创建一个进度条",但剪辑似乎没有按我预期的方式工作.这是我做错了什么还是我误解了什么?
应该剪辑的 draw()
例程:
@Override公共无效绘制(SpriteBatch 批次,浮动 parentAlpha){矩形剪刀 = new Rectangle();矩形clipBounds = new Rectangle(getX(), getY(), getWidth() * 0.75f, getHeight());ScissorStack.calculateScissors(getStage().getCamera(),getStage().getGutterWidth(),getStage().getGutterHeight(),getStage().getCamera().viewportWidth,getStage().getCamera().viewportHeight,批处理.getTransformMatrix(),剪辑边界,剪刀);如果(ScissorStack.pushScissors(剪刀)){super.draw(batch, parentAlpha);ScissorStack.popScissors();}}}
因为 draw
调用可能 会导致刷新发生,您需要将 draw
调用保持在 active-scissor 区域内.您可能还需要在启动活动剪刀区域之前刷新或结束批处理,以防止在剪刀开始在活动剪刀区域内刷新之前排队的绘制调用.
I'm trying to create a "progress bar" of sorts but the clipping doesn't seem to work the way I expect it to. Is this something I am doing wrong or something I've misinterpreted?
The draw()
routine that should clip:
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
Rectangle scissors = new Rectangle();
Rectangle clipBounds = new Rectangle(getX(), getY(), getWidth() * 0.75f, getHeight());
ScissorStack.calculateScissors(
getStage().getCamera(),
getStage().getGutterWidth(),
getStage().getGutterHeight(),
getStage().getCamera().viewportWidth,
getStage().getCamera().viewportHeight,
batch.getTransformMatrix(),
clipBounds, scissors);
if (ScissorStack.pushScissors(scissors)) {
super.draw(batch, parentAlpha);
ScissorStack.popScissors();
}
}
}
Complete sample code for ClipTest group class, TestScreen and screenshot.
ClipTest
is a subclass of group used to demonstrate the "bug".ClipImage
is a subclass of Image, which performs the clipping ondraw()
.ClipTest
has 2 images, background and foreground.
The background is a black image and it should always be the full size of the progress bar.
The foreground is a white image and it's width is clipped depending on the percentage of the bar.
The strange result I've found is that although the foreground is using the clipping class, the background image is the one actually clipped.
The expected result was created using photoshop (as I couldn't produce it via code).
Any idea what's wrong?
Actual drawing doesn't happen until the Batch "flushes", its not the draw
call you need to wrap, as that just queues up drawing to be done later.
You need to make sure the OpenGL draw calls happen between enabling and disabling your scissors, so add a flush
after the draw
. See
https://github.com/libgdx/libgdx/wiki/Clipping,-with-the-use-of-scissorstack
Because a draw
call might cause a flush to happen, you need to keep the draw
calls inside the active-scissor region. You may also need to flush or end the batch before starting the active scissor region to prevent queued draw calls from before the scissor start getting flushed inside the active scissor region.
这篇关于libgdx ScissorStack 未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:libgdx ScissorStack 未按预期工作


- 获取数字的最后一位 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 转换 ldap 日期 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01