How To Pause Your Game - GameMaker Studio 2

Поділитися
Вставка
  • Опубліковано 22 січ 2025

КОМЕНТАРІ • 55

  • @MxCrompli
    @MxCrompli 4 роки тому +11

    14:00
    Tip: Instead of calling "instance_find" 9 times you should make a new temporary variable and set it to what instance_find returns
    Example:
    var obj = instance_find(all, i);
    allObjects[i, 0] = obj.sprite_index;
    allObjects[i, 1] = obj.image_index;
    ETC
    This will make your code run SO much faster since it won't have to call the function 9 times to get the same value

  • @dynajay4106
    @dynajay4106 5 років тому +4

    Wow! This was incredibly helpful!
    I was actually going to do something kinda simple like take a screenshot and paste it over but I like your method better. Thanks for the video!

  • @BossAleks123
    @BossAleks123 3 роки тому

    4:36 i Stop button icon dissapears when i do this code, are there any else?

  • @ar_xiv
    @ar_xiv 3 роки тому +3

    To solve sprite ordering issues I needed to do the iteration in the draw event in reverse, so instead of the for loop, I did this:
    var i = array_height_2d(allObjects); while i-- {
    draw_sprite_ext ( ... )
    }

  • @GlitchyGamers18
    @GlitchyGamers18 2 роки тому

    the array_height_2d has become an obselete variable. Is there an alternative to reach the same result?

  • @friendlyneighborhoodvampir9081
    @friendlyneighborhoodvampir9081 4 роки тому +1

    Is there any way to stop from drawing sprites that are not visible? Such as transition areas and such.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  4 роки тому

      I’m not totally sure what you’re asking. If a sprite isn’t visible, it won’t be on the screen, which means it isn’t being drawn.

  • @sledge1693
    @sledge1693 2 роки тому

    Great tutorial, but I have a problem. I have a bullet object that stores different kinds of bullets in one sprite as different images, but when i pause the game with one of those bullet objects ingame, it shows a different bullet due to the image index changing. Please help!

  • @Alpha_beef
    @Alpha_beef 3 роки тому

    Hi! Im making a sidescroller game with a moving camera and I want to have the objects drawn at the same point as my camera. With this setup, it currently only draws objects at 0,0

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  3 роки тому

      I don’t really understand what you’re trying to do. A camera is just a way to view the game world, and the camera doesn’t really have a position, instead it has a spot you’re looking at.
      You can set a camera to follow an object, which sounds like what you want to do.

    • @Alpha_beef
      @Alpha_beef 3 роки тому

      @@LetsLearnThisTogether Im having a problem where certain objects are drawn in the wrong order. For example, I want to draw my player over an enemy object, but when the game pauses, the enemy is drawn over the player. How can I ensure that all objects are drawn at the correct depth?

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  3 роки тому

      Ah. So this video is pretty old and honestly not the best solution unless you need to access those objects while the game is paused. I would recommend looking into surfaces and capturing a screenshot of your game and then deactivating all instances except one, and drawing that screenshot in your game. That will pause the entire game and make everything stay exactly where it was before.

  • @Daywalkr
    @Daywalkr 4 роки тому +2

    That's a cool system. One small thing I'd like to point out is surely it's more efficient to assign instance_find(all, i) to a variable, and reference that variable within the for loop? Currently, you're calling instance_find 10 times per loop as opposed to once per loop. Small, but might help

  • @lildgamedev6885
    @lildgamedev6885 4 роки тому +1

    This works great thanks! Only thing is some instances in my game are marked as not visible, but they are drawn to the screen in my draw event. So I put this line
    if instance_find(all, i).visible == true {
    around my draw_sprite_ext code, but I get the error that unknown_object.visible not set before reading it. How can a built in variable not be set? By default all objects are set to visible so I'm not sure why I get this error, can anyone help plz?

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  4 роки тому +1

      Do you have an object called unknown_object? If not, put the debugger on that find all and follow it through to where it crashes. It should stop on the specific object that’s giving you problems, and then you can fix it.

    • @lildgamedev6885
      @lildgamedev6885 4 роки тому +1

      @@LetsLearnThisTogether wow thanks for the quick reply! I have been playing around with the debugger for the first time after watching this video so I really didn't know how to use it to find which specific object is giving the error. Ill give it another shot after reading this thanks!

    • @ar_xiv
      @ar_xiv 3 роки тому +2

      Kind of a hack but I solved this by putting "if !visible image_alpha = 0" in the create code for the object, or wherever you need to put it.

  • @CharlidiB
    @CharlidiB 4 роки тому

    Hi!
    Its reat tutorial!
    I manage to put some buttons on the pause scene by using an "Obj_button" where I draw them and a "obj_botton_spawner" and they are only active when de esc key is pressed. But the hover and interaction with the buttons doesnt work.
    How can I fix this? PLEASE HELP

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  4 роки тому

      Hmm, I don’t see why those interactions would fail. Are you saying you only draw them while the escape key is being held?

    • @CharlidiB
      @CharlidiB 4 роки тому

      @@LetsLearnThisTogether No, sorry for not explaning myself well. I opened an if statement around the part of the code that activates the buttons, like:
      " if (gamePause == true) " then the hover function and the buttons appear, so when the pause function becomes "true" the buttons appear. Im also deactivatting the button objects when "gamePaused == false" and activating the when its "true".
      Am I taking a bad approach?
      Thank you so much for answering.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  4 роки тому +1

      That’s not necessarily a bad approach, but if that’s your only check then I think you’re creating a new button every frame of your game, yeah? Sometimes have many objects when there should only be 1 causes weird issues. Check your debugger and see how many buttons you actually have in your game.

    • @CharlidiB
      @CharlidiB 4 роки тому +1

      @@LetsLearnThisTogether Ok ok
      I'll check that. Thank you so much!

  • @ngame_gamer4498
    @ngame_gamer4498 4 роки тому

    I cant get the code to work. I could Get the pause thing to work. But if I wanted the sprites to stay I could not get it to work

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  4 роки тому

      Try downloading my project and comparing the code to yours.
      If you’re getting an error, post the full error.

  • @stal2496
    @stal2496 5 років тому

    it doesnt work anymore :/ . i get an error that i havent said if it was flase or true before if statement. if i do esc key does nothing

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  5 років тому

      What exactly is the error?

    • @stal2496
      @stal2496 5 років тому

      @@LetsLearnThisTogether here imgur.com/a/4psMsQG when i do set it to something esc doesnt do anything anymore

    • @inventarium6591
      @inventarium6591 5 років тому

      @@stal2496 You need to set the variable "gameispaused" in the create event

  • @NightNinja
    @NightNinja 4 роки тому

    great tutorial! the game pauses and unpauses well with not many problems, sadly though the problems that do occur are pretty drastic. I'm not sure what's causing it since I haven't seen anyone else talk about it but pausing the game creates some pretty game breaking visual glitches and layering issues. For example when I pause in the second room of the game for some reason sprites from the previous room will pop up on screen, they go away once I unpause but it's still quite annoying, also when I pause and unpause the rooms layers get really messed up along with the objects in them. It seems like the objects get replaced into the room in the order they were created/put in instead of the layers they are on. I don't know I probably made some mistake in the code or something, still it's a great tutorial that does exactly what it promises! thanks

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  4 роки тому +1

      I haven't seen those issues, so that's crazy! But yeah, I'd say that doesn't quite work the way you need, sorry for that.

    • @NightNinja
      @NightNinja 4 роки тому

      @@LetsLearnThisTogether It's fine, it was a great tutorial anyway! I'll give an update if I figure out what's causing the glitch.

    • @ar_xiv
      @ar_xiv 3 роки тому +1

      @@NightNinja see my comment it might help with the layering

  • @igorthelight
    @igorthelight 6 років тому +5

    9:20 - Wrong! It works like that in other languages, but not in GML! "i" will be destroyed after WHOLE event "Key Press - Escape" will be executed.
    It's easy to check:
    for (var i = 0; i < 10; i++)
    {
    }
    new_variable = i;
    That will not create a mistake. "new_variable" will be equal to 10.

    • @igorthelight
      @igorthelight 6 років тому +2

      Otherwise, very informative video!

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  6 років тому +2

      Yep, you're correct. I made that mistake in this video, but have fixed it in future videos.

    • @igorthelight
      @igorthelight 6 років тому +3

      It's kinda illogical, so it's ok to make this mistake :-)

  • @SilentLesch
    @SilentLesch 6 років тому +2

    You could just catch all the objects at application surface, store the surface, and then just draw it until unpause.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  6 років тому +2

      Very true. That way is much simpler and faster.
      If, however, you want to do anything with paused objects then you have to do something like this.

  • @Taencred
    @Taencred 6 років тому

    Hi Beyond Us Games. I have another problem that I'm not able to solve.
    When paused, other objects start to appear on top of the player. I assume this has to do with the fact that they're redrawn after the player and therefore end up on top in the paused state. For example, if I walk up to a wall, I've made it so that the collision check only checks the bottom of my character, and therefore the character is beheaded by the wall when I pause. Any suggestion for an easy fix on controlling in which order things are redrawn during the pause? Sorry if I'm just missing something simple here but I'm rather new to data structures and arrays overall.
    Cheers.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  6 років тому

      Hmm, I don't know if there is a simple solution, but what I'd recommend is figuring out what you need on top, and then you can assign depth to those items specifically.
      So when you redraw things, check if the object id is that of your player, and if so, set it's depth lower so it's always on top.
      Make sense?

    • @Taencred
      @Taencred 6 років тому

      Thank you for the quick response.
      Where do you mean for me to check the object id? The idea makes sense to me, but I don't understand how I can assign the depth to the player during the pause since it is just being drawn and is not associated with its object. Can I set the depth of sprites without objects?
      The idea I had was to somehow move the player's entry in the array to the bottom so that it is drawn last.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  6 років тому

      Yeah, so you might not have the id, with the current project. So if you add another row in the array, you can capture the object id. Then check it against the player id, such as
      If objPlayer == array[I].object_index
      Set depth to lower.

    • @Taencred
      @Taencred 6 років тому +1

      I see, thanks a lot :)
      Great video btw, helped a lot. I'm trying to learn the whole idea of data structures atm since I've started on a much larger project than what I've previously done. These videos are a great resource. Liked every single one :)

    • @arseniodelacruziii2452
      @arseniodelacruziii2452 6 років тому +1

      FreakyIdiota I love the video and how you explain everything, can't wait to try this out.

  • @gdomjan83
    @gdomjan83 6 років тому

    Thanks for the tutorial. I read about a similar way to do this, which proved to be working quite well for me. Just before you deactivate the objects, you take a screenshot of the screen and display it. You do it through creating a sprite from the applicaton surface and save that sprite in a varible. Then draw the sprite on the surface. This way I didn't have to manage all the different objects. And when unpaused you destroy the sprite.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  6 років тому +1

      Yeah, that works too. It would be much simpler.

    • @BlastTheBat
      @BlastTheBat 6 років тому

      @@LetsLearnThisTogether Yeah I did that and it worked better.

  • @elminncf7083
    @elminncf7083 7 років тому

    nice work!

  • @AqareCover
    @AqareCover 7 років тому

    thanks for this helpful video, and your udemy course also seems to be interesting. are you actually planning to make an advanced udemy course one day?

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  7 років тому

      Indeed I do. Not sure yet, but it's on the radar. Got anything specific you hope to see in it?

    • @AqareCover
      @AqareCover 7 років тому

      Cool! I'm especially interested in RPG's and RPG battle systems.

    • @LetsLearnThisTogether
      @LetsLearnThisTogether  7 років тому +1

      +AqareCover Ah yes, I am, too.

  • @rorysimmonds
    @rorysimmonds 4 роки тому

    To anyone watching this who has the issue where sprites are drawn at the wrong depth, the solution is to use a grid rather than an array, as there are functions to easily sort grids.
    You'll need to add an extra column to the grid to store the depth of the sprite.
    To use this, just have a controller object somewhere that has the line 'global.pause = true' on whatever key press you want to pause the game.
    docs.google.com/document/d/1_OTP54M70aKUhLGnBZL42TCznJdtjBnxRSEPrBRUp7s/edit
    I'm fairly sure that this will still have the issue that items on the same layer may change order arbitrarily, so you might get some weird popping when you pause. I'm sure it can be solved by doing something like checking the current sprite draw order, and using that to add a small amount to each sprite. You could do something like work out the instance draw order than multiply that by 0.00001, then adding that to the depth. The end result would be that the draw order for all items would be preserved. You'd run into issue if the amount ever ran over 100 hence why you can choose an arbitrarily small number.
    Also worth noting that you can get a cool silhouette effect by just replacing the image blend with c_black, as it will only affect the sprites and not the background.

    • @ar_xiv
      @ar_xiv 3 роки тому +1

      I solved it by iterating the draw statements in reverse.
      var i = array_height_2d(allObjects); while i-- {
      draw_sprite_ext ( ... )
      }