• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Need a hand with surface and lighting!

Jihl

Member
Hey there!

I need to apply a lighting effect on my game depending on the players position, the room is very big so I can't draw a black screen on the whole room or it gets laggy.

This is the draw event of my obj_lighting_controller

Code:
var b = 600
var c = 1000
if !surface_exists(lSurf)
    lSurf = surface_create(2000, 2000)

surface_set_target(lSurf)
draw_set_color(c_black)
draw_set_alpha(nightAlpha)
draw_rectangle(playerX-b, playerY-b, playerX+b, playerY+b, false)

gpu_set_blendmode(bm_subtract)
draw_set_color(c_white)

with oLight {
    for (var i = 0; i<array_length_1d(radius_array); i++) {
        draw_set_alpha(nightAlpha/(i+1))
        var radius = radius_array[@ i]
        draw_circle(x-playerX+c, y-playerY+c, radius, false)
    }
}

gpu_set_blendmode(bm_normal)
surface_reset_target()
draw_set_alpha(1)
draw_surface(lSurf, playerX-c, playerY-c)
And the effect I get is this
https://gyazo.com/88aaf90475e9f3e5637c3d2fef288b6f

Which has all the lights well positioned but the farer I get from the 0,0 position it seems that the "correct" surface is being drawn away from the player
https://gyazo.com/d2e0b4e1ef41b73b53d026a4c4fa5a4e

Any help will be greatly appreciated! ^^
 

Jihl

Member
I made it work! the problem was that I was drawing the rectangle depending on the player's position even when the surface was the target, so it had to be something like:

draw_rectangle(playerX-b, playerY-b, playerX+b, playerY+b, false)
or
draw_clear_alpha(c_black, 0.4)
 
Top