Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX Lightning Effect Code  (Read 250149 times)
0 Members and 1 Guest are viewing this topic.
Offline Phased
« Posted 2015-02-11 04:16:00 »

To an Android Game I am currently developing slowly, I thought a Lightning effect would look good to link and show something is in effect.

I first tried to create my own Lightning, but my first go didn't look exactly as I wanted it.

I remembered seeing a post about someone sharing some source code on a game, and decided to look for it.

After talking to Cero about his lightning code here, I went through with it and implemented it into my game.

Since implementing the code into my game, I decided to modify Cero's original code, to make it more friendly to use, by setting some methods to private and also adding a few duplicate methods to allow more control or less code required to use.

Source Code
Source Code can be found here

Implementation
The GFX class is completely static, you do not need to create a new instance of it, just supply the texture once, and use it when you need to.

During your creation of the game, in the create() method add the line
1  
GFX.setTexture(new Texture("image.png")); //set a texture for it to use, 1x1 white image is all that is required



Preview of the effect:

Default Chain Lightning
Click to Play


Red and Yellow Chain Lightning
Click to Play


Multi Coloured Chain Lightning
Click to Play


Chain Lightning in a random position
Click to Play


Default Sphere Lightning
Click to Play


Red and Yellow Sphere Lightning
Click to Play


Multi Coloured Sphere Lightning
Click to Play



Using a 1x1 white image will produce the lightning a little differently to what is seen in the previews, if you would like the image I used you can get it here

If you have any suggestions for improvements, let me know, and I will see what I can do.

Thanks to Cero for letting me use his code, the original can be found here.
Offline atombrot
« Reply #1 - Posted 2015-02-11 11:06:46 »

Nice... Thanks for sharing. Might probably have a use for this in my project.
Offline Cero
« Reply #2 - Posted 2015-02-11 12:04:46 »

When I wrote this code a year ago I made this video:

<a href="http://www.youtube.com/v/j7DX4Eyrh-Y?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/j7DX4Eyrh-Y?version=3&amp;hl=en_US&amp;start=</a>

the texture, the filtering, shaders, adding particle effects and some clever coding can make this stuff way more beautiful of course.
Also to make it simpler @Phased took out a performance enhancement where I use the Sqrt class with precalculated values to speed up the get distance calculation

Furthermore note that this code was not intended for third party use and was just part of my code base and I posted it, meaning it might still be clunky and there are some hardcoded values to some extend.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Phased
« Reply #3 - Posted 2015-02-11 12:15:56 »

Also to make it simpler @Phased took out a performance enhancement where I use the Sqrt class with precalculated values to speed up the get distance calculation

Furthermore note that this code was not intended for third party use and was just part of my code base and I posted it, meaning it might still be clunky and there are some hardcoded values to some extend.

Actually, I just changed from my getDistance() to your original implementation.

Looking through the code again, in your original implementation, you decided to use the getDistanceAccurate() method, which is the code implemented in the one on this thread.

Your Trigonemtrics class had getDistanceAccurate() and getDistanceFast(), and your GFX class used getDistanceAccurate().


About the hard coded variables, there is a few, but I did mess around with them, and then numbers you chose in my opinion are the actual "magic number" they made it look the best in my opinion.

I was going to add a method to set them, so the user could customize it, but I didn't worry as it didn't really improve it.
Offline Cero
« Reply #4 - Posted 2015-02-11 15:33:03 »

Your Trigonemtrics class had getDistanceAccurate() and getDistanceFast(), and your GFX class used getDistanceAccurate().

Really huh ? Well the code is a year old so there goes my memory. Should be fine with the fast variation... I might change it in my code base

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5504 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5766 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

EgonOlsen (4660 views)
2018-06-10 19:43:48

EgonOlsen (5681 views)
2018-06-10 19:43:44

EgonOlsen (3196 views)
2018-06-10 19:43:20

DesertCoockie (4094 views)
2018-05-13 18:23:11

nelsongames (5114 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!