how to flip a pixmap to draw to a texture in libgdx?(如何翻转像素图以绘制到 libgdx 中的纹理?)
问题描述
所以我要做的是通过将像素图绘制到纹理来为我的游戏生成背景图像.到目前为止,我可以做到这一点,但现在我需要将在 X 或 Y 轴上翻转的像素图绘制到纹理上.但是我找不到任何事情要做.pixmap 类不提供该功能.然后我想我可以将翻转的纹理区域绘制到纹理上,但到目前为止我还没有找到如何做到这一点.所以我想知道我该如何做这样的事情,是否可以使用其他 java 库翻转 png 图像,然后从翻转的图像创建像素图?
So what I'm trying to do is to generate a background image for my game by drawing pixmaps to a texture. So far I can do that, but now I need to draw the pixmaps flipped in the X or Y axis to the texture. However I can't find anything to do so. The pixmap class does not provide that functionality. Then I thought I could draw a flipped texture region to a texture, but so far I haven't found how to do so. So I was wondering how can I do such a thing, would it be possible to flip a png image with other java libraries and then create a pixmap from that flipped image?
推荐答案
除了迭代像素,我也没有看到其他选项:
I also don't see other option except to iterate the pixels:
public Pixmap flipPixmap(Pixmap src) {
final int width = src.getWidth();
final int height = src.getHeight();
Pixmap flipped = new Pixmap(width, height, src.getFormat());
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
flipped.drawPixel(x, y, src.getPixel(width - x - 1, y));
}
}
return flipped;
}
这篇关于如何翻转像素图以绘制到 libgdx 中的纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何翻转像素图以绘制到 libgdx 中的纹理?
基础教程推荐
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01