带有最近过滤的 libgdx tiledmap 闪烁 [英] libgdx tiledmap flicker with Nearest filtering

查看:20
本文介绍了带有最近过滤的 libgdx tiledmap 闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将相机夹在玩家(box2d-Body)上滚动时,我在平铺地图上出现了奇怪的伪影.

I am having strange artifacts on a tiledmap while scrolling with the camera clamped on the player (who is a box2d-Body).

在遇到此问题之前,我使用线性过滤器处理平铺地图,以防止出现这些奇怪的伪影,但会导致纹理渗色(我直接从 .tmx 文件加载平铺地图而不填充平铺).

Before getting this issue i used the linear filter for the tiledmap which prevents those strange artifacts from happening but results in Texture bleeding (i loaded the tiledmap straight from a .tmx file without padding the tiles).

但是现在我使用的是最近的过滤器,它可以消除流血,但是当滚动地图时(通过夹着凸轮的角色行走),它看起来像很多像素在周围闪烁.闪烁结果可能会变得更好或更糟,具体取决于相机的缩放值.但是当我使用 libgdx-Utilities 中的OrthoCamController"类时,它允许通过用鼠标/手指平移来滚动地图,我根本没有得到这些工件.我认为闪烁可能是由 box2d-Body 的位置接收到的错误相机位置值引起的.我应该在这里添加一件事:游戏实例以 1280*720 显示模式运行,而我的游戏摄像机仅渲染 800*480.我将游戏摄像头的渲染解决方案更改为 1280*720,但我没有得到那些伪像,但瓷砖太小了.

However now i am using the Nearest filter instead which gets rid of the bleeding but when scrolling the map (by walking the character with the cam clamped on him) it seams like a lot of pixel are flickering around. The flickering results can get better or worse depending on the cameras zoom value. But when I use the "OrthoCamController" class from the libgdx-Utilities which allows to scroll the map by panning with the mouse/finger i don't get these artifacts at all. I assume that the flickering might be caused by bad camera-position values received by the box2d-Body's position. One more thing i should add here: The game instance runs in 1280*720 display mode while my gamecam renders only 800*480. Wen i change the gamecam's rendersolution to 1280*720 i don't get those artifacts but then the tiles are way too tiny.

有没有人遇到过这个问题或知道如何解决这个问题?:)

Has anyone experienced this issue or knows how to fix that? :)

推荐答案

我也遇到过类似的问题,发现是因为相机位置的十进制值太小了.

I had a similar problem with this, and found it was due to having too small a decimal value for the camera position.

我认为可能发生的情况是在 tilemap 渲染器中对某些 tile 列/行进行了某种舍入.

I think what may be happening is some sort of rounding with certain tile columns/rows in the tilemap renderer.

我通过四舍五入到设定的精度来解决这个问题,如下所示:

I fixed this by rounding to a set accuracy, like so:

camera.position.x = Math.round(player.entity.getX() * scalePosition) / scalePosition;

用各种值进行实验,但我通过使用图块大小作为 scalePosition 值来实现它.

Experiment with various values, but I got it working by using the tile size as the scalePosition value.

这篇关于带有最近过滤的 libgdx tiledmap 闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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