• 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!

Windows Need help

G

Giang Gia Hùng

Guest
hey guys, I'm creating a Pause Menu for the game. While the game is pausing the string is still getting input and it's still drawing the text on the screen. Can someone explain to me why the instance_deactivate(all) doesn't work on this? (Here are the codes):

GML:
//o_Pause event Create

gameIsPaused = false;
allObjects[0,0] = noone;


//o_Pause event Key Press Escape

/// @description Pause the game
if(gameIsPaused == false) {
    gameIsPaused = true;
    var offset = 0;
    for(var i = 0; i < instance_count; ++i) {
        if(instance_find(all, i).sprite_index != -1) {
            allObjects[i - offset, 0] = instance_find(all, i).sprite_index;
            allObjects[i - offset, 1] = instance_find(all, i).image_index;
            allObjects[i - offset, 2] = instance_find(all, i).x;
            allObjects[i - offset, 3] = instance_find(all, i).y;
            allObjects[i - offset, 4] = instance_find(all, i).image_xscale;
            allObjects[i - offset, 5] = instance_find(all, i).image_yscale;
            allObjects[i - offset, 6] = instance_find(all, i).image_angle;
            allObjects[i - offset, 7] = instance_find(all, i).image_blend;
            allObjects[i - offset, 8] = instance_find(all, i).image_alpha;
        }
        else
            ++offset;
    }
    instance_deactivate_all(true);
}
else {
    instance_activate_all();
    gameIsPaused = false;   
    allObjects = 0;
}


//o_Pause Draw event

/// @description While game is paused
if(gameIsPaused) {
    draw_set_color(c_white);
    draw_set_font(fnt_coders_crux);
    draw_text(room_width/3, room_height/2, "GAME IS PAUSED");
    
    for(var i = 0; i < array_height_2d(allObjects); ++i) {
        draw_sprite_ext(allObjects[i, 0], allObjects[i, 1], allObjects[i, 2],
        allObjects[i, 3], allObjects[i, 4], allObjects[i, 5], allObjects[i, 6],
        allObjects[i, 7], allObjects[i, 8] / 2);
    }
}




// o_Textbox Step event
/// @description Handle Keys Presses/Input

if(o_Pause.gameIsPaused == false)
if(keyboard_check(vk_anykey) and string_length(text) < 15)
{
    if(keyboard_string >= chr(97) && keyboard_string <= chr(122))
    text = text + string(keyboard_string);
    keyboard_string = "";
}



// o_Textbox Draw event

/// @description Draw the Text
draw_self();

draw_set_color(c_white);
draw_set_halign(fa_left);
draw_set_valign(fa_middle);
draw_set_font(fnt_coders_crux);
draw_text(x+7,y+20,text+cursor);
 

Amon

Member
It might have something to do with the draw order. By the looks of it you are drawing the text last which means it'll be ontop of everything else, even when you are paused.
 
G

Giang Gia Hùng

Guest
It might have something to do with the draw order. By the looks of it you are drawing the text last which means it'll be ontop of everything else, even when you are paused.
"A deactivated instance effectively ceases to exist in the game, but individual instances can still have their variables accessed. "
i read this about the instance_deactivate function on GMS. Maybe it's not because of the draw order. I think it's still getting the variables accessed
 
Top