B
Brillmedal
Guest
So originally I've got 16 sets of this code block messily creating a surface each all within a single draw event; since they're all similar blocks I decided to figure out scripts and tidy it up since the variables are easy enough. I translated it directly into a script with no changes in logic.
(Bear in mind the code worked fine before, I just wanted to learn+tidy)
So I am calling this script from my draw event (obj\_roof\_surface)
with
Now it "*appears*" to work, but even with only one script it quickly accumulates megabytes of memory until it slows to a crawl. I assume it's recreating the surface every step or something? I was of the impression scripts could use the variables from within the object that they were called so why is this happening?
I tried variations of drawing and setting targets before or/and after the call script event but weird things are now happening with the surface; and it just doesn't seem right.
I'm very, very confused. Should I be using global surfaces or just avoid creating surfaces within scripts all together?
To clarify, in my obj create event I set the surface variable up
roof_a = -1
Any help is appreciated cause I don't know how to move this forward really
Thanks
(Bear in mind the code worked fine before, I just wanted to learn+tidy)
So I am calling this script from my draw event (obj\_roof\_surface)
GML:
function scr_set_roof_surface(argument0,argument1,argument2)
{
if !surface_exists(argument1)
{
argument1 = surface_create(global.vw*1.2,global.vh*1.2)
}
surface_set_target(argument1);
draw_clear_alpha(c_black,0)
gpu_set_blendmode(bm_normal);
var lay_id = layer_get_id(argument0); //get layer id to grab for draw
var map_id = layer_tilemap_get_id(lay_id);
if !(keyboard_check(vk_space))
{
gpu_set_blendmode(bm_normal)
draw_tilemap(map_id,-round(global.avx),-round(global.avy)); //draw at 0 but subtract the view coords
gpu_set_blendmode(bm_normal)
}
//draw glow
with(obj_player)
{
gpu_set_blendmode(bm_subtract);
draw_sprite_ext(spr_light,0,x-round(global.avx),y-round(global.avy),sight_size,sight_size,0,c_black,1);
draw_circle_colour(x-round(global.avx),y-round(global.avy), 50, c_white, c_black, 0);
gpu_set_blendmode(bm_normal)
}
draw_set_alpha(argument2)
surface_reset_target();
draw_surface(argument1,round(global.avx),round(global.avy));
draw_set_alpha(1)
}
GML:
scr_set_roof_surface("Roof_A", roof_b, global.roof_a_alpha)
I tried variations of drawing and setting targets before or/and after the call script event but weird things are now happening with the surface; and it just doesn't seem right.
I'm very, very confused. Should I be using global surfaces or just avoid creating surfaces within scripts all together?
To clarify, in my obj create event I set the surface variable up
roof_a = -1
Any help is appreciated cause I don't know how to move this forward really
Thanks