• 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 How to wait until surface is resized before screenshotting (Studio 1.4)

skeddles

Member
I'm trying to take a screenshot of my entire room. I pieced together this code from another thread:

GML:
view_xview[7] = 0;
view_yview[7] = 0;
view_wview[7] = room_width;
view_hview[7] = room_height;
view_enabled[7] = true;
window_set_rectangle(0, 0, room_width, room_height);
surface_resize(application_surface, room_width, room_height);

var file = get_save_filename("*.png", "screenshot");
surface_save(application_surface, file);
The code works, except for one caveat: it takes the screenshot before the screen is done resizing. The screenshot saved looks like the screen before it was resized. If I do it a second time, THEN it gives me the proper screenshot, since the screen is already resized from the last time.

Is there any way for me to wait until the screen is done resizing before saving the screenshot?
 

skeddles

Member
Thank you for the idea! I have figured it out finally. A little different from what you said, but still the same concept.

In my create event, I initialize exportState = 0

In my keypress event, I changed it to just get the filename, and set the flag to 1

GML:
file = get_save_filename("*.png", "screenshot.png");
exportState=1
And finally, in the step event, I added this code, which does half of the work one frame, then the rest on the next frame:

GML:
//STEP 1 - resize view
if (exportState == 1) {
    
    //save window position for resetting
    windowx = window_get_x();
    windowy = window_get_y();

    //switch to export view and resize to fit the whole screen
    view_visible[7] = true;
    window_set_rectangle(0, 0, room_width, room_height);
    surface_resize(application_surface, room_width, room_height);
    
    //next step
    exportState = 2;
}

//STEP 2 - export and revert
else if (exportState == 2) {
    
    //save the surface to a file
    surface_save(application_surface, file);
    
    //reenable the default view
    view_visible[7] = false;
    view_visible[0] = true;
    
    //reset the room size / position
    window_set_rectangle(windowx, windowy, view_wview[0], view_hview[0]);
    surface_resize(application_surface, view_wview[0], view_hview[0]);
    
    //done, reset flag
    exportState = 0;
}
I ended up removing the part that resized the view to fit the room size, and just configured the view to match by default (though if you needed to you could still do it dynamically)

Posting this in the slim chance that someone else is trying to figure this out finds this thread, and not all the other terrible ones with no clear answer :D
 
Top