没有 box2d 的 Libgdx 灯

2022-01-12 00:00:00 box2d java libgdx lighting box2dlights

我刚开始使用 libgdx 创建游戏.这是一个使用scene2d ui的自上而下的2d射击游戏.现在我想,我可以为某些级别添加黑暗和光明,但我不想使用 box2d 重写所有内容.我不需要逼真的阴影,只需要某种环境光和围绕我的角色的光环,它不受墙壁和他周围其他障碍物的影响.所以我想知道libgdx中是否有任何类型的光系统?或者我可以在不使用 box2d 身体/世界的情况下使用 box2dlights 吗?谢谢

I just started creating a game using libgdx. It is a top down 2d shooter using scene2d ui. Now i thought, that i could add darkness and light to some levels, but i don't want to rewrite everything using box2d. I don't need realistic shadows just some kind of ambient light and a lightcircle arround my character, which is not affected by walls and other obstacles arround him. So i wanted to know if there is any kind of lightsystem in libgdx? Or can i use box2dlights without using box2d bodies/world...? Thanks

推荐答案

不幸的是,LibGDX 已经没有提供类似的东西了.

Unfortunately there is nothing like this already provided by LibGDX.

但如果你不想要阴影,你可以自己轻松地做到这一点.

But you can easily do it yourself if you do not want shadows.

这里是一个通过 LibGDX 完成的小视频.这里是文章到这个视频,带有代码和描述以及提供的所有内容.您可以使用着色器以这种方式执行此操作,但您也可以通过将光照贴图渲染到 FBO 来执行相同操作(在给定的链接中您可以看到如何执行此操作),然后以通常的方式渲染它,并在顶部激活混合你的屏幕.标准的 SpriteBatch 可以做到这一点,您不需要任何自定义着色器.

Here is a little video of someone who has done it via LibGDX. Here is the article to this video, with code and descriptions and everything provided. You can do it this way with shaders, but you could also do the same by just rendering a lightmap to an FBO (in the given links you can see how to do that) and then just render it the usual way with blending activated on top of your screen. The standard SpriteBatch can do that and you don't need any custom shaders.

如果你仍然想要有障碍物的真实阴影,你可能会发现 这篇 文章非常有用.但这要慢得多,并且需要特殊的着色器.

If you still want to have real shadows with obstacles, you will probably find this article very useful. But this is a lot slower and needs special shaders.

顺便说一句,没有 Box2D 也无法使用 Box2dLights.

There is also no way to use Box2dLights without Box2D btw.

相关文章