問題描述
我剛開始使用 libgdx 創(chuàng)建游戲.這是一個使用scene2d ui的自上而下的2d射擊游戲.現(xiàn)在我想,我可以為某些級別添加黑暗和光明,但我不想使用 box2d 重寫所有內(nèi)容.我不需要逼真的陰影,只需要某種環(huán)境光和圍繞我的角色的光環(huán),它不受墻壁和他周圍其他障礙物的影響.所以我想知道libgdx中是否有任何類型的光系統(tǒng)?或者我可以在不使用 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 已經(jīng)沒有提供類似的東西了.
Unfortunately there is nothing like this already provided by LibGDX.
但如果你不想要陰影,你可以自己輕松地做到這一點.
But you can easily do it yourself if you do not want shadows.
這里是一個通過 LibGDX 完成的小視頻.這里是文章到這個視頻,帶有代碼和描述以及提供的所有內(nèi)容.您可以使用著色器以這種方式執(zhí)行此操作,但您也可以通過將光照貼圖渲染到 FBO 來執(zhí)行相同操作(在給定的鏈接中您可以看到如何執(zhí)行此操作),然后以通常的方式渲染它,并在頂部激活混合你的屏幕.標準的 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.
如果你仍然想要有障礙物的真實陰影,你可能會發(fā)現(xiàn) 這篇 文章非常有用.但這要慢得多,并且需要特殊的著色器.
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.
這篇關(guān)于沒有 box2d 的 Libgdx 燈的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!