Games [XUI2D] Anyone knows how to make light effects or emulate light source for a game?

JGParamo

Active Member
Licensed User
Has anyone been able to use XUI2D or X2 to make a light shader that can be cross-platform? Any library or code snippet using XUI2D or something that can be used with little modification between B4A and B4J may do (shown image is done using LibGDX in B4A), thanks.

1617409116179.png
 

angel_

Well-Known Member
Licensed User
Longtime User
Maybe this will help you:

 

JGParamo

Active Member
Licensed User
Maybe this will help you:


Thank you, I will look at it.. :)
 

JGParamo

Active Member
Licensed User
Maybe this will help you:


It looks like the samples show specific effects on the whole image or its border. I may start from it, though my particular interest is on certain portion of an image, say a circular area similar to that when pointing a flashlight to a photo in a dark environment where the circular light pattern is soft at the edge.
 
Last edited:

JGParamo

Active Member
Licensed User
Perhaps this can be interesting?


Thank you, i'll check it then.. :)
 

JGParamo

Active Member
Licensed User
Perhaps this can be interesting?


No codes or the like provided but gives very useful concepts for a good 2D game that mimics a 3D effect and space by using sprites, color shades, 3D light simulation, shadows, etc.. thanks for sharing the link.. :)
 

ilan

Expert
Licensed User
Longtime User
with libgdx and it is very simple and you also have examples for that. if you want to do it for ios than iSpritekit is the right tool: https://www.b4x.com/android/forum/threads/rapid-cube-ispritekit-game.90094/#content

i am not sure xui2d has a possibility to use shaders. libgdx and iSpritekit do but there is no cross-platform solution for that right now. it depends on what you want to do in your game. there are some tricks that you can do light effects without using shaders. Again it all depends on the effect you want to archive.

like: https://b4x.com/android/forum/threads/glowing-ball-status-approved.49833/

and many other ways...
 

JGParamo

Active Member
Licensed User
@ilan your glowing ball game is interesting. Btw I've seen how lighting effects is done using libGDX. I just want to make it crossplatform so if XUI2D don't have such capability as of this moment, I may drop my intent of a common code between platforms and opt for libGDX when developing for mobile device and jLibGDXemulator for pc game. Just not sure if jLibGDXemulator already have the needed functionalities as its author as I understood it mentioned it to be still lacking the complete LibGDX capabilities. I hope @Erel can give comments on how XUI2D could implement such lighting effects even if it could turn out to be of complex work-around codes, say BitmapCreator's DrawCircle with edge blurring and fill color with alpha/transparency or fill gradient perhaps.. :)
 
Last edited:

ilan

Expert
Licensed User
Longtime User
there are many technics to make lightning effects without any library. for example, the image im post #1 can be done in a simple way.
you have 1 texture that is the wall then you have another texture that is basically a dark background with a gradient to the center from black with alpha of let say 150 to transparent. now you just move the image with your player and you get a nice light effect. i did this in my Pixel Knight game (made with Libgdx). have a look at it here:

 

JGParamo

Active Member
Licensed User
there are many technics to make lightning effects without any library. for example, the image im post #1 can be done in a simple way.
you have 1 texture that is the wall then you have another texture that is basically a dark background with a gradient to the center from black with alpha of let say 150 to transparent. now you just move the image with your player and you get a nice light effect. i did this in my Pixel Knight game (made with Libgdx). have a look at it here:


Wow, such a nicely made game it is and that glowing and animated light as the player moves in dark areas. It seems i would need to stay with LibGDX for the moment while crossplatform using XUI2D has yet to provide similar capability (unless i could make or find XUI2D codes to achieve the same :) ). My gratitude for you sharing these ideas...
 
Last edited:

ilan

Expert
Licensed User
Longtime User
It seems i would need to stay with LibGDX for the moment while crossplatform using XUI2D has yet to provide similar capability

the light effect i show you in the game can be made easily with xui2d as i don't use shaders for that. see the explanation on how to do it in post #10
 

JGParamo

Active Member
Licensed User
the light effect i show you in the game can be made easily with xui2d as i don't use shaders for that. see the explanation on how to do it in post #10

Ah okay, i may have missed that.. I will explore how this can be done in xui2d using textures, gradient and transparency.. :) Thanks.
 

ilan

Expert
Licensed User
Longtime User
gradient and transparency.

you create 2 bitmaps in any painting software you want. i use GIMP. then you draw the wall bitmap to the canvas and then you draw the dark bitmap above it. i attach a simple example using simple tools like b4xCanvas and that's it. NOTE that i draw each time I move the mouse the wall bitmap BUT because the wall bitmap is not changing you don't need to do that so you can draw it only once by using an imageview or in xui2d the relevant element. this is just an example to show you how it can be done.

run the b4j project and move the mouse above the image and you will get a simple but nice light effect :)

light.png
 

Attachments

  • sle.zip
    326.5 KB · Views: 274

JGParamo

Active Member
Licensed User
you create 2 bitmaps in any painting software you want. i use GIMP. then you draw the wall bitmap to the canvas and then you draw the dark bitmap above it. i attach a simple example using simple tools like b4xCanvas and that's it. NOTE that i draw each time I move the mouse the wall bitmap BUT because the wall bitmap is not changing you don't need to do that so you can draw it only once by using an imageview or in xui2d the relevant element. this is just an example to show you how it can be done.

run the b4j project and move the mouse above the image and you will get a simple but nice light effect :)

View attachment 110961

Thank you @ilan, your code works and saves some effort to re-invent the wheel, i may do my intended app/game cross platform with xui2D.. :D
 

ilan

Expert
Licensed User
Longtime User
But dont forget this!

NOTE that i draw each time I move the mouse the wall bitmap BUT because the wall bitmap is not changing you don't need to do that so you can draw it only once by using an imageview or in xui2d the relevant element.

draw only what is needed and something that does not change. this will increase your game performance ;)

Good Luck!
 
Top