Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Game #5, Balls Out! > Time for action — enhancing the OnObjectTouch method

Time for action — enhancing the OnObjectTouch method

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. Inside the OnObjectTouch method, do a SELECT on the object's tag value. Method OnObjectTouch:Int(obj:ftObject, touchId:Int) Select obj.GetTag() Check against the constant btnPlay, that is, the Play button: Case g.btnPlay Play the Select sound and start a new game: g.sndSelect.Play() g.StartNewGame() Check against the btnBack constant. This is the Back button: Case g.btnBack 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 Check against the btnExit constant. This is the Exit button: Case g.btnExit End the game with a call to the Error method, with an empty string: Error("") 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.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint