Pause Tutorial
JGary321
Member Posts: 1,246
The community here has helped me with many problems. I figured I would give back by doing a tutorial on how to implement a "Pause" system. This is how I did mine. I am sure there are many ways of doing it. To alot of people all this may be common sense, but I'm sure some will find it helpful. I am not a pro at writing a tutorial, so bear with me. Also I am at work, so I am going by memory. Also if anyone has questions about setting up a Pause system, please ask them hear. Maybe we can get something similar up on the "How-To" Wiki...
Without Furtherado::
First thing you need to do is set a "Boolean" Game Attribute. I called mine "Game Paused". I have it set to 1 (so the game starts paused).
Second for each moveable actor you have to setup a Pause Rule. This is done wherever you have the Move command on the actor. For example, I have it so my enemy mobs randomly choose a location to move to toward my castle. I place that "Move-To" command within a rule that states (actor attribute changed, game.Game Paused = FALSE). If you have an animation for the actor that also goes under that rule.
What this does is that if the game attribute Game Paused = 0(false) then the actor moves/animates as normal. Otherwise it stands still.
You basically do this for every actor that can be changed. For instance I have a game attribute called Game Time. My Game Time starts at 30 secs & I used a timer that says every 1 second that game.Game Time = game.Game Time -1. (this deducts 1 second every 1 second) I put that timer under a rule that says (actor attribute changed, game.Game Paused = FALSE). So essentially the Timer only works if game is not paused.
I also made a text box that shows the Game Paused=True, that says "Game Paused". I made a second by right under that that says "Tap to Continue". I created an attribute that says when the text box is tapped to changed game.Game Paused-False. (this unpauses the game)
Bah, that stupid text box is still there! That's easy let's Destroy it after the game is unpaused.... Not a good idea. I guess technically you could destroy/respawn when it is un paused, but i took the easy way out. See that Otherwise part of your Rule? The one that most people don't ever use?? Well I created another text box. In the text box I put a "." & then made is translucent, so you can't see it. Less work on my part, but you can do it either way.
You can now also setup a button that if game.Game Paused = 0, change attribute game.Game Paused = 1. You don't need to setup then pushing the button again, b/c we already set that up in the text box.
That completes my tutorial, I know it's probably not the best written, but hopefully it will help someone. I plan on creating more tutorials on different things, if everyone likes this one, (& if it's ok with the moderators). Thanks guys for the support you have shown me, hopefully this helps in some way.
-JGary
Without Furtherado::
First thing you need to do is set a "Boolean" Game Attribute. I called mine "Game Paused". I have it set to 1 (so the game starts paused).
Second for each moveable actor you have to setup a Pause Rule. This is done wherever you have the Move command on the actor. For example, I have it so my enemy mobs randomly choose a location to move to toward my castle. I place that "Move-To" command within a rule that states (actor attribute changed, game.Game Paused = FALSE). If you have an animation for the actor that also goes under that rule.
What this does is that if the game attribute Game Paused = 0(false) then the actor moves/animates as normal. Otherwise it stands still.
You basically do this for every actor that can be changed. For instance I have a game attribute called Game Time. My Game Time starts at 30 secs & I used a timer that says every 1 second that game.Game Time = game.Game Time -1. (this deducts 1 second every 1 second) I put that timer under a rule that says (actor attribute changed, game.Game Paused = FALSE). So essentially the Timer only works if game is not paused.
I also made a text box that shows the Game Paused=True, that says "Game Paused". I made a second by right under that that says "Tap to Continue". I created an attribute that says when the text box is tapped to changed game.Game Paused-False. (this unpauses the game)
Bah, that stupid text box is still there! That's easy let's Destroy it after the game is unpaused.... Not a good idea. I guess technically you could destroy/respawn when it is un paused, but i took the easy way out. See that Otherwise part of your Rule? The one that most people don't ever use?? Well I created another text box. In the text box I put a "." & then made is translucent, so you can't see it. Less work on my part, but you can do it either way.
You can now also setup a button that if game.Game Paused = 0, change attribute game.Game Paused = 1. You don't need to setup then pushing the button again, b/c we already set that up in the text box.
That completes my tutorial, I know it's probably not the best written, but hopefully it will help someone. I plan on creating more tutorials on different things, if everyone likes this one, (& if it's ok with the moderators). Thanks guys for the support you have shown me, hopefully this helps in some way.
-JGary
Comments
If you want, you can add this to the wiki how-tos.
I was thinking of something along the same lines but for a sound on/off function!
Would be very interested in reading more!
Thanks again!
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
Also, went ahead & threw this up on the tutorial wiki.
http://gamesalad.com/wiki/game_pause_tutorial
If key pressed = up
If game.pause = 0
Then accelerate...etc...
Now the one thing I 'don't know is how well it will resume. Like if the car will start back over at speed 0 or what. So lemme know how it turns out.
Your timer rule would be
If game.paused = false then Every 1 sec self.timer = self.timer-1.
The spawn rule would be
When self.timer = 0 then spawn actor & change attribute self.timer = (whatever the initial spawn time is)
Make sense??
If self.timer > 0 & game.pause = false then every .7 secs spawn enemy.