• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED] surface_copy + surface_draw only draws a blank surface

C

Caique Assis

Guest
Hello! So, I tried today to make a little pause system with surfaces. The general idea is that if the game is paused, the application surface would be copied into a surface I created using the surface_copy function, and after that, I deactivate all instances. except my controller instance (where the surface code is running). The problem is, when I draw the surface, I only get a "blank surface". Here is my current code:

CREATE EVENT

Code:
pause = false;

surf = surface_create(room_width,room_height);
surface_set_target(surf);
draw_clear_alpha(c_black,0);
surface_reset_target();
STEP EVENT
Code:
if(keyboard_check_pressed(vk_enter)){
    pause = !pause;
}

if(pause){
    if(surface_exists(surf)){
        surface_set_target(surf);
        draw_clear_alpha(c_black,0);
       
        surface_copy(surf,0,0,application_surface);
       
        surface_reset_target();
    }else{
        surf = surface_create(room_width,room_height);
    }

    instance_deactivate_all(true);
}else{
    if(surface_exists(surf)){
        surface_free(surf);
    }

    instance_activate_all();
}
DRAW EVENT
Code:
if(pause){
    if(surface_exists(surf)){
        surface_set_target(surf);
        draw_clear_alpha(c_black,0);
       
        draw_surface(surf,0,0);
       
        surface_reset_target();
    }else{
        surf = surface_create(room_width,room_height);
        surface_set_target(surf);
        draw_clear_alpha(c_black,0);
        surface_reset_target();
    }
}
Yes, I'm making sure my controller object has the lowest depth, and it's the first instance being created in the room. I'm not using views or anything of the sort because this was just a simple test. I read somewhere that you need to use surface_copy in the draw event, but that didn't seem to work. I've already tested things without setting the surface target too, only setting it in the draw event, but didn't seem to work.

In my mind, simply copying the application_surface to my created surface would already do all of the job, without me needing to loop through all the instances and add their sprites to the surface.

Anyway, any help is appreciated. Thanks!
 

obscene

Member
The application_surface is cleared at the end of each draw cycle, and nothing else is drawn to it until the next draw cycle begins. If you are copying it during the step event, this is AFTER it's been cleared but BEFORE it's being drawn to.
 
C

Caique Assis

Guest
Ok, so here's the problem with my code.

In my step event, I was check if the surface I created existed, and if it did, I copied the application surface to it. If it didn't, I just created the surface, but didn't copy the application surface. The problem is that, the first time the step event was being executed, the surface didn't exist, so I created a new one but didn't copy the application surface. This made it so that I created a new one, deactivated all instances, and in the next step calls the surface would exist, but the application surface would be blank, making it appear blank when I draw the surface. Also, I've found out that I was clearing the surface before drawing it - this was making it appear blank. Here's the fixed code:

CREATE EVENT
Code:
pause = false;

surf = surface_create(room_width,room_height);
surface_set_target(surf);
draw_clear_alpha(c_black,0);
surface_reset_target();
STEP EVENT
Code:
if(keyboard_check_pressed(vk_enter)){
    pause = !pause;
}

if(pause){
    if(surface_exists(surf)){
        surface_copy(surf,0,0,application_surface);
    }else{
        surf = surface_create(room_width,room_height);
        surface_set_target(surf);
        draw_clear_alpha(c_black,0);
        surface_reset_target();
        surface_copy(surf,0,0,application_surface);
    }

    instance_deactivate_all(true);
}else{
    if(surface_exists(surf)){
        surface_free(surf);
    }

    instance_activate_all();
}
DRAW EVENT
Code:
if(pause){
    if(surface_exists(surf)){
        draw_surface(surf,0,0);
    }
}
 
Top