java - 如何在 LibGDX 中为动画设置过滤器?
问题描述
我为动画制作了一个带有小精灵(32x32)的精灵表。我遇到了动画看起来非常模糊的问题。有人告诉我尝试添加我不太清楚如何为动画添加过滤器,所以如果有人可以帮助我,将不胜感激,谢谢。 .setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
解决方案
您不能TextureFilter
直接将 a 设置为动画,因为 anAnimation
不知道什么是动画。但是由于动画由Texture
s 组成,因此您可以将 a 设置为动画内TextureFilter
的Texture
s。
这如何完成取决于您如何创建动画。如果您加载纹理并创建它们的动画,您可以这样做:
Texture texture = new Texture(Gdx.files.internal("path/to/your/image.png"));
texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
// load the other textures of the animation in the same way
Texture[] allTextures = loadOtherTexturesWithFilter();
// create the animation
final float frameDuration = 0.1f;
Animation<Texture> animation = new Animation(frameDuration, allTextures);
或者,如果您Texture
以不同的方式加载 s,您可以从 s 中获取Texture
sAnimation
并更改它们的过滤器:
//here the generic type of the Animation needs to be Texture or some subclass of texture (like TextureRegion, ...)
Animation<Texture> animation = yourAnimation;
for (Texture texture : animation.getKeyFrames()) {
texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
}
推荐阅读
- python - 如何在 pytest requests mock 中伪造我的回复
- javascript - plotly - 响应宽度,固定高度
- kubernetes - 如何管理基于微服务的应用程序的逻辑分组以确保 CI/CD 管道的版本兼容性?
- excel - 在隐藏和取消隐藏用户表单之间移动时出错
- python-3.x - 如何将数字列表排列成列和行
- elasticsearch - logstash 不会读取单行文件
- linux - 将 Windows Docker 主机中的 Linux 容器连接到外部网络
- android - android studio和sqlite计算重复值
- mysql - 在带有like运算符的sql查询中使用星号标记
- javascript - 用 JS 编码的 Html 的 Wordpress 交换 &&