Monkey needs a SetPausedImage() method

Monkey Forums/Monkey Programming/Monkey needs a SetPausedImage() method

CGV(Posted 2013) [#1]
On some types of games you have to cover up the screen when the game pauses/loses focus so the player can't cheat.

There's presently no way to do that but a SetPausedImage() method, which I think would be easy to implement, would solve that problem.

You simply tell monkey what image to use and the coordinates to draw it at, defaulting to 0,0, and before Monkey pauses the app it draws it on screen.

I know a lot of people would prefer a more complex pause system be implemented in Monkey but that would require a major rewrite. What I'm suggesting should be trivial to add.

EDIT: We would also need to be able to change the image while the game is running as you might want a different image displayed over various sections of the game. (e.g: on the title screen you may just want the word "Paused" displayed but on the game screen you would need to cover up the game board as well.)


therevills(Posted 2013) [#2]
I would prefer it to call OnRender one last time, something like this:
Strict

Import mojo

Function Main:Int()
	New MyGame()
	Return 0
End

Class MyGame Extends App
	Field paused:Bool
	
	Method OnCreate:Int()
		paused = False
		SetUpdateRate 60
		Return 0
	End
	
	Method OnUpdate:Int()
		Return 0
	End
	
	Method OnRender:Int()
		Cls
		DrawText "RENDER", 10, 10
		If paused
			Cls
			DrawText "PAUSE", 10, 10
		End
		Return 0
	End
	
	Method OnSuspend:Int()
		paused = True
		Return 0
	End
	
	Method OnResume:Int()
		paused = False
		Return 0
	End
End



CGV(Posted 2013) [#3]
I've been giving it some more thought and now I feel the best approach would be for Monkey to have a global pause variable that always indicates the focus state of the app.

By monitoring that variable in your OnRender and OnUpdate methods you can implement your own pause functionality any way you want. Monkey would play no role in pausing the game.

Among other things this would allow for a pseudo pause state were you can display a menu of options for the player to choose from like what Origaming was talking about in this thread.


Gerry Quinn(Posted 2013) [#4]
It's something you can easily code your self as part of a standard framework/methodology.

In my case I typically have a global 'playTime:Float' which is updated only when the gameplay is not paused. There is also a gameTime:Float that keeps running in case I want to do animations anyway, e.g. on option buttons, or if I wanted to animate the 'Paused' image. Both get updated (or not) on every OnUpdate().

On some systems a focused-state variable might be handy - you could check that in OnUpdate() before deciding how to increment gameTime and playTime.

The timer values are an adjunct to a state value which indicates what gets drawn during OnRender(). For example, if you have an options menu showing, that should be known by reading a state variable. In OnUpdate() you then do not increment playTime, and you read the option buttons. And in OnRender() you draw (perhaps) the game in a faded fashion, and then draw the option buttons on top. If the buttons flash when pressed, gameTime is still incrementing so they can tell what colour they should be.


CGV(Posted 2013) [#5]
It's something you can easily code your self as part of a standard framework/methodology.

On what target platform(s) are you doing this?

I don't see how it would be possible in Flash or HTML5 which are the targets I'm most interested in.

If you set AUTO_SUSPEND to True your app instantly pauses when it loses focus preventing you from so much as drawing a "Game Paused" message, hence my request for a SetPausedImage() method and therevills' alternate suggestion.

If you set AUTO_SUSPEND to False your app never receives any notification that it's lost focus so it obliviously just keeps chugging along.

A global boolean that indicates the focus state of the app or the OnSuspend and OnResume methods always working regardless of the AUTO_SUSPEND setting would solve all these problems on every platform.


Monkey's current auto suspend feature is great when you just need to stop the app from running but in my current game the player can cheat but simply clicking off the game window so I can't release it until this issue is addressed.


Gerry Quinn(Posted 2013) [#6]
I agree that a suspended flag would be useful in some situations. What I was saying was that there is no need for an elaborate and necessarily inflexible 'paused graphics' system. [If it is done, I think it should be as a module.]

As for Flash and HTML5, most of what I do is click-driven anyway. People shouldn't be losing focus willy-nilly, so I think a pause button on screen (or detect keypress 'P') would be adequate for an arcade game anyway.


ElectricBoogaloo(Posted 2013) [#7]
I've hit this dilemma on many occasions, and .. at the end of the day, my rule has been "This can happen, people will cheat, it isn't important."

If your game relies on layout vs time, say it's a word game, or a jigsaw, or a match-3, or something like that, then an easy way to cheat is to hit PrintScreen, pause the game (even with a blockade), paste the screenshot, work out the method, unpause the game, beat the game.
It's doable, and it's one simple button that's integrated into the OS, which is letting you do it.
Similarly, you can screengrab on iOS, and .. hopefully by now a decent number of Android versions also have screengrabbing capabilities, too.

It can, and more than likely will happen.
You can't possibly deal with it by simply slapping up a big Pause thing.

If you're doing local-scoreboards, it doesn't matter at all.
If you're doing online-scoreboards, be sure you've got a "Friends list", so that people don't have to deal with those morons with multi-bazillion-point scores who only cheat so their name is up at the top.

At the end of the day, this is less about "Pause", and more about securing your game.
.. And if you want to be really paranoid about it, you could always make it so the game quits if it ever gets paused..


Capn Lee(Posted 2013) [#8]
Very well said


therevills(Posted 2013) [#9]
Say you have an action game and the user changes application then moves back to the game, I would like it to display a pause screen so the player doesnt die straight away - but it would look odd that clicking back in the window that the pause menu pops up then (OnResume) instead of popping up when the pause happens (OnSuspend)...


CGV(Posted 2013) [#10]
Some of the responses to my suggestion lead me to believe that some of you guys are Richard Stallman weird or you just misunderstood what I was saying.

I think it's silly to view this as a philosophical issue. This is a simple technical issue and a shortcoming of Monkey.

Here's my feature request reconsidered and presented as succinctly as possible:

If AUTO_SUSPEND is set to True Monkey handles the pause. If it's set to False we handle the pause but either way the OnSuspend/OnResume methods need to be called.


marksibly(Posted 2013) [#11]
> If AUTO_SUSPEND is set to True Monkey handles the pause. If it's set to False we handle the pause but either way the OnSuspend/OnResume methods need to be called.

This could be done, however you'd need to take care of: pausing all audio/music and, if you want to be polite, letting the user get some CPU back when the game is paused by adjusting the update rate. This is stuff that's already taken care of for you on all targets.

If all you're after is a 'paused' screen, then my preferred solution would be to tweak the flash/html5 targets so OnRender is called once after app is suspended, allowing you to set a flag and wack up a 'paused' screen. This should be easy to do, and doesn't introduce any new 'special cases' to how Monkey works.


CGV(Posted 2013) [#12]
If all you're after is a 'paused' screen, then my preferred solution would be to tweak the flash/html5 targets so OnRender is called once after app is suspended, allowing you to set a flag and wack up a 'paused' screen. This should be easy to do, and doesn't introduce any new 'special cases' to how Monkey works.

That meets my needs. Thanks Mark!


therevills(Posted 2013) [#13]
then my preferred solution would be to tweak the flash/html5 targets so OnRender is called once after app is suspended,

Also GLFW/XNA?


marksibly(Posted 2013) [#14]
glfw already seems to work - just done xna.

If you want to try 'em out, new versions of html5/flash/xna targets are now up at github in the develop branch.