How it´s possible make a torch flame effect or Light?¿

Previous topic - Next topic

mentalthink

Hi there...

well this it´s my question, I like to add a nice effect like a torch in my game, but I don´t know how make it succes...

Bassicaly it´s have the background very darknnes, and when the "light" pass" over the screen, we can see the background lightings... (ike in old School Games... the corners of the lights are blurred.)

I try 2 modes, whit and image and another like the "torch" playing whit alpha values, but I don´t look very nice the effect...

And the second mode... whit polyvectors, making a grid, and triying to change the alpha in the vertex, when the torch pass over them... but I don´t makes works...

Any suggestion or help for make this...

Thanks in advance...
Iván J,

Darmakwolf

Maybe something sort-of-kind-of like this? I'd also try using just a round light image and using positive-value alpha. Also this example is likely not very helpful... but hey it sort of does stuff. :P

[attachment deleted by admin]

MrTAToad


mentalthink

@Darmakwolf Thanks a lot, I try you example and it´s perfect!!! I only have to modify a few things... because my GFX stuff don´t it´s like toon graphics... but it´s absolutetly prefect!!! thanks a lot!!!, just yesterday I thinked about the masking....

@MRTatoad thanks a lot for you new "program" in this case I can´t use in this part of the game... but I try it your code and it´s very very usefull... only a counsil, I think It´s more friendly if your use teh sliders you made whit the DDGUI, and auto update--- I thin if you impement for make and atlas can be, a good application for explosion and cool 2d FX...

Thanks to both... very helpfully and interensting things in this Post!!!  :good: :good: :good: :booze:

Slydog

Cool effect Darmakwolf!

I used your code as my base, and updated it to use an alpha gradiently transparent png instead.
This gets rid of the ring effect.
I had to blank out the areas surround the light sprite as a result.

Also, I updated to remove hard coded values. 
Now it reads the sprite and screen sizes at the start.

See the screenshot at the bottom, it may explain it better.

Code (glbasic) Select
SETCURRENTDIR("Media") // go to media files
SETTRANSPARENCY RGB(255,0,255)
LOADSPRITE "lght.png", 0
LOADBMP "loz.PNG"

GLOBAL mx%, my%, b1%, b2% // Mouse x, y, Buttons 1, 2
GLOBAL sx%, sy% // Screen size x, y
GLOBAL xl%, xr%, yt%, yb% // Sprite Left, Right, Top, Bottom
GETSCREENSIZE sx, sy

// Calculate 1/2 sprite size
GLOBAL sp_x%, sp_y%
GETSPRITESIZE 0, sp_x, sp_y
sp_x = sp_x / 2
sp_y = sp_y / 2

GLOBAL rgb_bg% = RGB(0,0,0) // Background colour - Black

WHILE TRUE
SMOOTHSHADING TRUE
ALPHATESTING 0
MOUSESTATE mx, my, b1, b2

// Keep light inside screen
IF mx < 0 THEN mx = 0
IF mx > sx THEN mx = sx
IF my < 0 THEN my = 0
IF my > sy THEN my = sy
// IF mx < sp_x THEN mx = sp_x
// IF mx > sx - sp_x THEN mx = sx - sp_x
// IF my < sp_y THEN my = sp_y
// IF my > sy - sp_y THEN my = sy - sp_y

// Calculate the locations of the four sides of the sprite
xl = mx - sp_x // X Left
xr = mx + sp_x // X Right
yt = my - sp_y // Y Top
yb = my + sp_y // Y Bottom

// Blank out the portions above, below, left, and right of sprite
DRAWRECT 0,   0,    sx,    yt, rgb_bg // Cover Top
DRAWRECT 0,  yb,    sx, sy-yb, rgb_bg // Cover Bottom
DRAWRECT 0,  yt,    xl, yb-yt, rgb_bg // Cover Left
DRAWRECT xr, yt, sx-xr, yb-yt, rgb_bg // Cover Right

// Draw transparent 'light' sprite at mouse location
ALPHAMODE -1.0
DRAWSPRITE 0, xl, yt

SHOWSCREEN
WEND


[EDIT] Ooops, it looks like I added too much transparency to the light sprite.  You can see the hard edges of the surrounding 'blank out' rects.  Just change the light sprite to make sure it has solid values around the perimeter.

[EDIT2] Added 'ALPHATESTING 0' to main loop.  Uploaded new 'lght.png' to fix boxed / hard edge bug.

[EDIT3] Updated code to keep light on screen.  Now allows it to go right to the edge.

(Only update code on this page, not the included project)


[attachment deleted by admin]
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

mentalthink

Only for if someone need... I needed a effect in cone form... like when you make a spot light whit 45 degrees in the cone... for make those effect it´s very similar...

Make the same code Darmakwolf but for use the image you use 2, the blackimage whit hole, and the hole, but deleting the white (blurred) part of this circle black image...

Whit this can have a lintern effect and turning around it self...

Darmakwolf

I like the smoothness there, sly, but I see a sort of box on the outside of it... there must be a way to get rid of that  :|

Slydog

See my first post for the fixes.

Ha, ya, I realized that too late and added an update to report the bug:
Quote[EDIT] Ooops, it looks like I added too much transparency to the light sprite.  You can see the hard edges of the surrounding 'blank out' rects.  Just change the light sprite to make sure it has solid values around the perimeter.

So I created a new 'lght.png' file to get rid of the problem.
(Then I needed the 'ALPHATESTING 0' command to get rid of the funny circle near the center, where the alpha gets near zero:
Quote[EDIT2] Added 'ALPHATESTING 0' to main loop.  Uploaded new 'lght.png' to fix boxed / hard edge bug.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]