Game Development Reference
In-Depth Information
We set a listener for the system event if we want to catch the events such as the following:
The applications starts (when the user taps the icon)
The app is placed into suspension (when the user presses the home button and the
app is in the background)
The app is resumed (when the app is started again from the previous state rather
than from the beginning)
The app exits.
Runtime:addEventListener("system",
function(event)
print("System event : " .. event.type)
end)
In other instances when the device is reoriented (i.e., changed from portrait mode to landscape). We
can catch that with the orientation event.
Runtime:addEventListener("orientation",
function(event)
print("Orientation changed to.. event.type)
end)
Note The system events cannot be seen in the Corona simulator or terminal window, as they
require the Apple iOS simulator or an actual device to function. However, the applicationStart ,
applicationSuspend , and applicationResume events can be generated in the Corona simulator.
Custom Events
In addition to the system events, you can also have custom events—events that you create specifically
for your application. This way, you can manage the asynchronous portions of your game. Let's
say the game involves a boss battle with a gigantic spider; each time you take a limb off the giant
spider, you can raise an event that will add a special bonus to your score and/or make the spider do
something specific at that moment. With a game in the style of a top-down plane-shooter, you could
use the events to update the score as you hit each plane.
Let's say we have a function that increases the score by a specified number; these parameters are
passed to the function in a table-type structure:
function updateScore(event)
local score = lblScore.score + event.points
lblScore.text = score
lblScore.score = score
end
 
 
Search WWH ::




Custom Search