且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

libgdx剪切图像

更新时间:2023-11-10 19:56:52

您想使用Libgdx公开的OpenGL Scissor支持。请参阅 Libgdx Clipping wiki
Libgdx ScissorStack 文档

You want to use the OpenGL Scissor support that Libgdx exposes. See the Libgdx Clipping wiki and the Libgdx ScissorStack documentation.

API不是特别友好(它旨在支持动态推送多个限制矩形,据我所见,经常不经常使用。)

The API isn't particularly friendly (its designed to support dynamically pushing multiple constraining rectangles, which as far as I've seen, isn't used very often).

要记住剪刀堆栈的重要一点是它只适用于发出的实际绘制命令。由于大多数API都尝试批量绘制命令,这意味着当它看起来应该发生时,可能不会发生实际绘图。为了确保发生剪裁,你必须在推剪刀之前冲洗任何缓冲的绘图(否则错误的东西可能会被修剪)并且你必须在弹出剪刀之前清除任何绘制调用(否则你想剪裁的东西可能会避免剪刀)。

The important point to remember with the scissor stack is that it only applies to actual draw commands that get issued. Since most APIs try to batch up draw commands, this means actual drawing might not happen when it looks like it should happen. To ensure clipping is happening you must flush any buffered draws before pushing the scissor (otherwise the wrong thing might get clipped) and you must flush any draw calls before popping the scissor (otherwise things you want clipped might avoid the scissors).

请参阅 libgdx ScissorStack未按预期工作libGDX - 如何剪辑如何使用SpriteBatch在屏幕的一部分上绘图在libgdx?使一个组隐藏在其边界之外的演员