Time for action — creating a StartNewGame method

In this method, make use of the CreateAtomElements method that we have built before:

  1. In the game class, add a new method called StartNewGame.
    Method StartNewGame:Int()
    
  2. First, set the game score to 0.
    score = 0
    
  3. Next, deactivate the title layer. Because of this, it won't be rendered and doesn't act on touch hits from the user.
    layerTitle.SetActive(False)
    
  4. Now, remove all objects from the game layer (if there are any).
    layerGame.RemoveAllObjects()
    
  5. Set the collCount field to 0. This will be used as an increasing ID for collision checks.
    collCount = 0
    
  6. Finally, call the method that will create the grids of atom elements.
    CreateAtomElements()
    
  7. The last step is to set the game mode to gmPlay and close this method:
    gameMode = gmPlay
    Return 0
    End
    

What just happened?

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.

Time-related movement

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset