The OnUpdate
method of the game
class is responsible for calculating the delta time since the last frame and updating the game, depending on which mode it is in.
Select
statement on the game mode.Method OnUpdate:Int() Local d:Float = Float(eng.CalcDeltaTime())/60.0 If isSuspended = False Then eng.Update(Float(d)) Select gameMode
gmPlay
.Case gmPlay
If eng.TouchHit(0) Then eng.TouchCheck(layerGame) Endif
If layerGame.GetObjTransCount()= 0 Then
FillTiles()
ClearGems() Endif
StartNewGame
.If KeyHit(KEY_N) Then StartNewGame()
If KeyHit(KEY_ESCAPE) Then ShowMenu()
UpdateInfoText()
gmGameOver
constant.Case gmGameOver
If eng.TouchHit(0) Or KeyHit(KEY_ESCAPE) Then gameMode=gmMenu ActivateLayer(gameMode) Endif
gmScore
constant. If there is a 'touch hit', then conduct a 'touch check' on the score layer.Case gmScore If eng.TouchHit(0) Then eng.TouchCheck(layerScore)
gmMenu
constant. Again, if there is a 'touch hit', then conduct a touch check on the menu layer.Case gmMenu If eng.TouchHit(0) Then eng.TouchCheck(layerMenu)
gmTitle
constant. If the Esc key is pressed, activate the menu layer.Case gmTitle If KeyHit(KEY_ESCAPE) Then gameMode=gmMenu ActivateLayer(gameMode) Endif End Endif Return 0 End
Now, the update phase is set in stone. When you build and run the app, you can now press Esc in the title screen and it will switch to the menu screen. From there, you will be able to show the score layer and also start a new game.
To remind you what the menu screen looks like in the game, have a look at the following screenshot :