P
ProExCurator
Guest
So I decided to use this lighting engine, but there is couple of problems with it.
For example when I'm trying to go fullscreen I get this:
Lighting engine (Download - http://www.masterxy.bplaced.net/download.php?i=load&n=1):
script - light_change_scale
script - light_update
Object - obj_control - Create Event:
Object - obj_control - Step Event:
Object - obj_control - End Step:
Object - obj_control - Draw Event:
...
So I made a "research" and found out that I have to create the surface in the Draw event as well, since a surface can be errased any time in graphics memory.
and I did... but the problem, that it's not helping...
For example when I'm trying to go fullscreen I get this:
Code:
##########################################################################################
ERROR in
action number 1
of Step Event0
for object obj_control:
Trying to use non-existing surface.
at gml_Object_obj_control_StepNormalEvent_1 (line 13) - draw_surface_ext(sur, x - sprite_width / 2, y - sprite_height / 2, 1, 1, 0, image_blend, 1);
##########################################################################################
script - light_change_scale
Code:
image_xscale = argument0;
image_yscale = argument1;
surface_free(sur);
sur = surface_create(sprite_width, sprite_height);
if !surface_exists(sur) {
sur = surface_create(sprite_width, sprite_height);
}
Code:
var xp, yp, lw, lh, imin, imax, i, pdmin, pdmax, minx, miny, maxx, maxy, a_min, a_max, a_test;
lw = sprite_width;
lh = sprite_height;
surface_set_target(sur);
draw_clear(c_black);
draw_sprite_ext(sprite_index, image_index, lw / 2, lh / 2, image_xscale, image_yscale, image_angle, c_white, 1);
with (obj_wall) {
minx = px[0];
miny = py[0];
maxx = px[0];
maxy = py[0];
imin = -1;
imax = -1;
a_test = point_direction(other.x, other.y, x, y);
a_min = -1;
a_max = -1;
for (i = 0; i < points; i++) {
if (px[i] < minx)
minx = px[i];
if (px[i] > maxx)
maxx = px[i];
if (py[i] < miny)
miny = py[i];
if (py[i] > maxy)
maxy = py[i];
pdmin = (point_direction(other.x, other.y, x + px[i], y + py[i]) - a_test + 360) mod 360;
pdmax = (a_test - point_direction(other.x, other.y, x + px[i], y + py[i]) + 360) mod 360;
if (pdmin > a_min && pdmin <= 180) {
a_min = pdmin;
imin = i;
}
if (pdmax > a_max && pdmax <= 180) {
a_max = pdmax;
imax = i;
}
}
if (rectangle_in_rectangle(x + minx, y + miny, x + maxx, y + maxy, other.x - lw / 2, other.y - lh / 2, other.x + lw / 2, other.y + lw / 2)) {
i = imin;
draw_primitive_begin(pr_trianglestrip);
do {
pd = point_direction(other.x, other.y, x + px[i], y + py[i]);
draw_vertex_color(x + px[i] - other.x + other.sprite_width / 2, y + py[i] - other.y + other.sprite_height / 2, c_black, 1);
draw_vertex_color(x + px[i] + lengthdir_x(height, pd) - other.x + other.sprite_width / 2, y + py[i] + lengthdir_y(height, pd) - other.y + other.sprite_height / 2, c_black, 1 - fade);
i += 1;
i = i mod points;
} until (i == (imax + 1) mod points)
draw_primitive_end();
}
}
surface_reset_target();
Code:
// MUST HAVE: Create a surface for drawing all the lights
sur = surface_create(room_width, room_height);
// Create a light
m = instance_create(0, 0, obj_light);
with (m) {
light_change_scale(3, 3);
// Update the light, so it's surface is drawn correctly
light_update();
}
Code:
// MUST HAVE: Draw all the lights to the surface
surface_set_target(sur);
draw_clear(c_black);
draw_set_blend_mode(bm_add);
with (obj_light) {
draw_surface_ext(sur, x - sprite_width / 2, y - sprite_height / 2, 1, 1, 0, image_blend, 1);
}
draw_set_blend_mode(bm_normal);
surface_reset_target();
Code:
// Update one light to follow the mouse
m.x = mouse_x;
m.y = mouse_y;
// Update this light to draw the correct shadows
with (m)
light_update();
Code:
// MUST HAVE: Draw the surface to the screen
if !surface_exists(sur){
sur = surface_create(room_width, room_height);
}
draw_set_blend_mode_ext(bm_dest_color, bm_zero);
draw_surface_ext(sur, 0, 0, 1, 1, 0, c_white, 1);
draw_set_blend_mode(bm_normal);
// Draw info
draw_set_color(c_white);
draw_text(0, 0, string(fps) + "fps#" + string(instance_number(obj_light)) + " lights#" + string(instance_number(obj_wall)) + " casters");
draw_set_color(c_black);
So I made a "research" and found out that I have to create the surface in the Draw event as well, since a surface can be errased any time in graphics memory.
and I did... but the problem, that it's not helping...
Code:
if !surface_exists(sur){
sur = surface_create(room_width, room_height);
}
Last edited by a moderator: