SOLVED Problem with pause / freeze using surface; image appears stretched.

ikonhero

Member
Hi,

I'm trying to make my game freeze / pause by deactivating all instances from a seperate pause instance. Before deactivating all instances I make a copy of the application surface.
After all instances are deactivated I draw this surface in the draw event of the oPause instance.

However, the image appears to be zoomed in quite a lot. I get to see a bunch if pixels from the top left corner of the screen all stretched out.

I tried using both the surface method as well as the sprite creation method. Both render the same results.

Here's my code just to be sure:

GML:
//oPause Step Event

if (keyboard_check_pressed(ord("P"))) {

    paused *= -1;

    if (paused == 1) && (initPause == true) {

        audio_play_sound(sndTest,1,0);

        pauseSurfW = surface_get_width(application_surface);

        pauseSurfH = surface_get_height(application_surface);

        pauseSurf = surface_create(pauseSurfW,pauseSurfH)

        surface_copy(pauseSurf,0,0,application_surface);

        instance_deactivate_all(true);

        layer_set_visible("Foreground",0);

        layer_set_visible("BgSprite",0);

        initPause = false;

    } 

    if (paused == -1) && (initPause == false) {

        surface_free(pauseSurf);

        instance_activate_all();

        layer_set_visible("Foreground",1);

        layer_set_visible("BgSprite",1);

        initPause = true;

    }

}


//oPause Draw Event

if (paused == 1) && (initPause == false) {

    draw_surface(pauseSurf,0,0);

}
As you can see I tried forcing the target surface to be the size of the application surface. But once it's drawn it shows up all zoomed in.

Some other info, as I assume it has to do with this:

room size: 270x100
view and viewport sizes: 160x90
game runs with fullscreen started.

Any idea what I'm doing wrong here?

Thanks!!!

Screenshot of paused screen:
paused.jpg
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
The application surface is a different size to the camera. If the game is low res (eg 280*120 or something like that), but you don't set the app surface to that size, then your app surface will be 1920x1080 or something. So, when you create a custom surface like you have done, it'll be WAY too big for the game camera resolution. Use draw_surface_stretched() to draw the surface, and set the width/height values to the width/height of the camera (NOT the view port, the camera).
 

ikonhero

Member
Thanks! Hadn't figured out to stretch the saved surface to the view size. Also I noticed I needed to save the view x and y at pausing to draw the surface at the correct position.

Looks perfect now!

For others who are reading this, here's the final code.

GML:
///Create event
//pausing
paused = -1;
initPause = true;
pauseSurf = -1;

///Step event
//pausing game
if (keyboard_check_pressed(ord("P"))) {
    paused *= -1;
    if (paused == 1) && (initPause == true) {
        audio_play_sound(sndTest,1,0);
        pauseSurfW = surface_get_width(application_surface);
        pauseSurfH = surface_get_height(application_surface);
        pauseSurf = surface_create(pauseSurfW,pauseSurfH)
        surface_copy(pauseSurf,0,0,application_surface);
        viewX = camera_get_view_x(view_camera[0]);
        viewY = camera_get_view_y(view_camera[0]);
        viewW = camera_get_view_width(view_camera[0]);
        viewH = camera_get_view_height(view_camera[0]);
        instance_deactivate_all(true);
        layer_set_visible("Foreground",0);
        layer_set_visible("BgSprite",0);
        initPause = false;
    }   
    if (paused == -1) && (initPause == false) {
        surface_free(pauseSurf);
        instance_activate_all();
        layer_set_visible("Foreground",1);
        layer_set_visible("BgSprite",1);
        initPause = true;
    }
}


///Draw event
if (paused == 1) && (initPause == false) {
    draw_surface_stretched(pauseSurf,viewX,viewY,viewW,viewH);
}


///Room end event

if surface_exists(pauseSurf) {
    surface_free(pauseSurf);
}
Thank you. Marking thread as solved.
 
Top