GameMaker Drawing surfaces

I

Ice Guy

Guest
For some reason, drawing onto surfaces behaves differently (I think) in GMS2.

Here's my code for some simple lighting:

Create Event
Code:
/// Create surface
xx = camera_get_view_width(view_camera[0]);
yy = camera_get_view_height(view_camera[0]);
pos_x = camera_get_view_x(view_camera[0]);
pos_y = camera_get_view_y(view_camera[0]);
offset = 20

light = surface_create(xx + offset, yy+ offset);

col_darkness = make_colour_hsv(0, 0, 240);

light_drawn = 0;
Step Event
Code:
/// Manage surface
surface_set_target(light);
draw_set_colour(col_darkness);
draw_rectangle(pos_x - offset/2, pos_y - offset/2, xx + pos_x + offset/2, yy + pos_y  + offset/2, false);
surface_reset_target();

xx = camera_get_view_width(view_camera[0]);
yy = camera_get_view_height(view_camera[0]);
pos_x = camera_get_view_x(view_camera[0]);
pos_y = camera_get_view_y(view_camera[0]);

if (!surface_exists(light)) {
    light = surface_create(xx + offset, yy + offset);
}
Draw Event
Code:
/// Draw surface
if (surface_exists(light)) {
    gpu_set_blendmode(bm_subtract);
    draw_surface(light, pos_x - offset/2, pos_y - offset/2);
    gpu_set_blendmode(bm_normal);
}


with (player) {
    var size = 256;
    surface_set_target(light);
    gpu_set_blendmode(bm_subtract);
    draw_ellipse_colour(x - size*(3/4) - other.pos_x, y - size*(1/2) - other.pos_y, x + size*(3/4) - other.pos_x, y + size*(1/2) - other.pos_y, c_orange, c_black, false);
    gpu_set_blendmode(bm_normal);
    surface_reset_target();
}
From this code, the result I get is that new ellipses are being drawn instead of updating the position of the ellipse when drawn, making the lighting very awkward. Can anyone help?
 
I

Ice Guy

Guest
Nevermind, sorted out the issue, a chunk of the code should be in the step event.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
What you are getting is what I'd expect as you do not appear to be clearing the surface between updates. So the "lights" are being overdrawn on the existing surface data. Call a draw_clear(c_black) or something on the surface before updating it with the new light positions.
 
Top