1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Need a hand with surface and lighting!

Discussion in 'Programming' started by Jihl, May 15, 2019 at 2:43 AM.

  1. Jihl

    Jihl Member

    Joined:
    Nov 26, 2018
    Posts:
    52
    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! ^^
     
  2. Jihl

    Jihl Member

    Joined:
    Nov 26, 2018
    Posts:
    52
    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)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice