Imagine you have
var moving that increases after button press and that you have
var switch that switches between true and false(boolean). If it’s true, it’s paused and button pressing doesn’t increase
var moving. When you press pause again, switch variable goes to false, and pressing button again increases moving.
var switch= true; if clicked on switch, switch get opposite of what it holds at moment of clicking on it.
Setting switch true initially also is good since before starting a game, it’s just as is paused …
This isn’t really possible to answer because it depends entirely on how the game is coded as to whether this is simple, as @codename11 describes, or extremely difficult. Need more context. What they describe is how it will work at a high level, but how it actually works in practise is something different.
Sorry, the code includes 3 images, and I can only send one image per post
I’ll try @codename11’s solution
Well, that how it works at a high level. What I meant was post some code or a link to some code, I’m not sure why you would need to post images
No, it doesn’t work.
What doesn’t work?? You haven’t told us what you’re doing, what you’ve tried, what you’re trying to achieve, where you’re stuck.
Edit: also, the description is fine. In the example there is only one value changing over time (normally there would be more), but there is a switch (
pause), and when it is on (true), then the values get frozen, when it is off (false) the values are not frozen. It can get extremely complex, but it still, at base level, has to work this way. Reality says this cannot work another way: it either works this way or it’s not pause functionality.
I mean the description doesn’t work in my game
What makes your game run over time? How do you stop that loop from running? And if you stop it, how do you start it again? Because the variable values that have been changed will remain as what they were at the point you stopped. And if you start it again they will start changing from that point. so…
The chicken leg is designed to fall, which really keeps the game going. The only other action is the cat moving when the arrow keys are pressed, the cat moves.
What specifically is making your game animate over time? There is a specific line of code, one line, that makes it move, and the function you are using has a companion function available that you can use to stop what it’s doing. That is what you have to stop, else the turkey leg will keep moving.
- If you stop that (and prevent the player movement from working, ie just don’t do anything when they hit the keys), then the game is in a paused state.
- Once you start it again (and allow the player movement to happen), the game is unpaused.
Set a variable “paused” as false. When you click the pause button, if “paused” is false, set it to true and do #1 above. If “paused” is true, set it to false and do #2 above