Game Development Reference
In-Depth Information
and like so Gideros Studio:
function addHandler(theEventName, theHandler, theObject)
local theObject = theObject or stage
theObject:addEventListener(theEventName, theHandler)
end
function removeHandler(theEventName, theHandler, theObject)
local theObject = theObject or stage
theObject:removeEventListener(theEventName, theHandler)
end
Now we've added handlers, we need to set up a listener for taps on the screen.
removeHandler(tapEvent, shoot)
addHandler(tapEvent, restartGame)
end
And the tapped handler can be defined as follows:
function restartGame(event)
-- restart the game by setting most of the values to defaults
wTime = 2
-- we can set the reinitialization code here; e.g., setting the values, repositioning elements, etc.
setVisible(txtGameOver, false)
setVisible(txtTapAgain, false)
score = 0
distance = 0
collected = 0
fuel = MAX_FUEL
lives = MAX_LIVES
setVisible(heli,true)
updateText(txtFuel, fuel)
updateText(txtScore, score)
updateText(txtSaved, saved)
updateText(txtLives, lives)
-- remove the handler that will restart the game removeHandler(tapEvent, restartGame) gameOver = false
-- add the handler to shoot bullets when tapped addHandler(tapEvent, shoot) end
Search WWH ::




Custom Search