Time for action — enhancing the OnObjectTouch method

The OnObjectTouch method has the object itself as a parameter, and the touch ID that was given optionally when the TouchCheck statement was called.

  1. Inside the OnObjectTouch method, do a SELECT on the object's tag value.
    Method OnObjectTouch:Int(obj:ftObject, touchId:Int)
    Select obj.GetTag()
    
  2. Check against the constant btnPlay, that is, the Play button:
    Case g.btnPlay
    
  3. Play the Select sound and start a new game:
    g.sndSelect.Play()
    g.StartNewGame()
    
  4. Check against the btnBack constant. This is the Back button:
    Case g.btnBack
    
  5. Play the Select sound, activate the title layer, and set the game mode to gmMenu:
    g.sndSelect.Play()
    g.layerTitle.SetActive(True)
    g.gameMode = g.gmMenu
    
  6. Check against the btnExit constant. This is the Exit button:
    Case g.btnExit
    
  7. End the game with a call to the Error method, with an empty string:
    Error("")
    
  8. Close the SELECT statement:
    End
    Return 0
    End
    

What just happened?

Our little game will react now to touch events. Every text button we will press is now functional. A new game will be started, but the objects still stay where they are. This will be changed in the update events of the engine class.

Controlling the ball—acting on object update events

We will want to control the ball through the accelerometer in our device. The perfect place is the OnObjectUpdate method of the fantomEngine. It will be called every time an object is updated.

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

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