In this method, make use of the CreateAtomElements
method that we have built before:
game
class, add a new method called StartNewGame
.Method StartNewGame:Int()
0
.score = 0
layerTitle.SetActive(False)
layerGame.RemoveAllObjects()
collCount
field to 0
. This will be used as an increasing ID for collision checks.collCount = 0
CreateAtomElements()
gmPlay
and close this method:gameMode = gmPlay Return 0 End
We have created a method that let us (re)start the game at any time. It takes care of all fields that need to be set to zero and removes any existing atom elements from the game layer.
Imagine you are playing the game on two devices that are very different when it comes to computing power and render speed. One is very fast and one is crawling. The fast one will be able to compute/update more times in a second, than the slow one. The game would run much faster on one system. To avoid this, we will measure the time it took from the last frame to the current one. This value in milliseconds will be one part of the speed factor for the Update
method of fantomEngine. This will ensure that the game updates at the same speed, no matter which device you play the game on.