libgdx剪切图像 [英] libgdx Cutting an image

查看:139
本文介绍了libgdx剪切图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图剪切一段时间的图像,我会解释为什么和我尝试过的东西。
所以我想创建一个hpbar,除了它不是一个酒吧而是一颗心,所以我觉得我只需要两张照片将它们画在彼此之上,然后切割一个让它显示为在hp中丢失,但我无法找到切割图像的方法。

I have been trying to "cut" an image for some time now, I ll explain why and what I tried. So I wanted to create an hp "bar" except it's not a bar but a heart and so I though it would be easy all I had to do is have two pictures draw them on top of each other and then just cut one to make it appear as in hp was being lost, but I was not able to find a way to cut the image.


  • 设置高度只是调整图像的大小,因为你可能已经猜到了

  • 我尝试使用textureRegion来破解它但它没有那么顺利

  • 我发现了一个名为clip begin的方法,它也使用了剪刀,但出于某种原因,似乎没有工作。

我可能是使用剪辑开始错误,但我真的找不到任何真正的文档,我正在做的是:

I might be using the clip begin wrong but I can't really find any real documentation on it, all I'm doing is:

image.clipBegin(x,y,height,weight);
image.clipEnd();

我差点忘了,我正在使用scene2d Image,可能是一个更好的解决方法但不确定会是什么。

I almost forgot, I'm using a scene2d Image, might be a better way to go around it but not sure what that would be.

我很感激如何做到这一点,谢谢。

I would appreciate any ideas on how to do this, thank you.

推荐答案

您想使用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?使一个组隐藏在其边界之外的演员

这篇关于libgdx剪切图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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