Inside the OnObjectTouch
method of the engine
class, we want to start a new game when the PLAY or RESET button are hit. If the EXIT button was hit, we want to end the game. And if an atom element got hit, we want to start a chain reaction.
Select
statement with a call to the object's GetTag
method.Class engine Extends ftEngine Method OnObjectTouch:Int(obj:ftObject, touchId:Int) Select obj.GetTag()
Case
statement with the game's grpAtom
constant. This identifies an atom element.Case g.grpAtom
If obj.GetTransitionCount() = 0 Then
90
degrees to its current angle and with a transition ID of 1
. This ID needs to be set so that the OnObjectTransition
method is called, once the transition is completed.obj.CreateTransRot(90,200, True,1)
collCount
field by 1
and set the objects ID with a negative collCount
value. We do this because we check against the ID later on.g.collCount += 1 obj.SetID(-g.collCount) Endif
Case
statement with the game's btnPlay
and btnReset
constants.Case g.btnPlay, g.btnReset
StartNewGame
method.g.StartNewGame()
Case
statement with the game's btnExit
statement.Case g.btnExit
Error
statement with an empty error text. Weird, but it works! Then, close the Select
statement:Error("") End Return 0 End
Save your code now, and then build and run it. All buttons are functional; you can even tap on an element, and it will rotate by 90 degrees.
The OnObjectTouch
event is called when the user hits the object with a finger or on a desktop with the left mouse click. We acted on the buttons to change game modes and started the first transition of a new chain reaction.
3.144.248.24