Game Development Reference
In-Depth Information
Note The parameters passed to the function are different for the mouse events than for the touch
events. The touch event has a record called touches , which is not present in a mouse event. This is
mainly because the user can place multiple fingers on the screen—so, each touches record has an
x,y-coordinates and ID, while the mouse event does not.
The touch event contains two records, touches and allTouches . touches is the current touch that
contains the x,y-coordinates and the ID, whereas allTouches is an array that contains all of
the touches records. To get the object that triggered the touch event, you can use the function
.
function onEnterFrame(event)
local xP, yP = img:getPosition()
xP = xP + xD*speed
yP = yP + yD*speed
if xP >= _W-wd or xP == 0 then xD = −xD end
if yP >= _H-ht or yP == 0 then yD = −yD end
img:setPosition(xP, yP)
end
img:addEventListener(Event.ENTER_FRAME, onEnterFrame)
The enter frame event has a frameCount property, which returns the number of frames that have
passed since the start of the application. time returns the time in seconds since the start of the
application, and deltaTime contains the time difference between the last frame and the current
frame. This can be used in animation and can help to coordinate time-sensitive animation.
System Events
The stage object is present for the lifetime of the application. We can set up listeners on the stage
object just like we can on other display objects. The suggested way to manage system events is to
set them on the stage object. However, system events are like a broadcast, they are sent to every
object that sets up a listener, not exclusively to one.
 
Search WWH ::




Custom Search