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
Step Event
Draw Event
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?
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;
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);
}
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();
}