2 Questions

Hey guys, I have 2 questions today.

  1. When your making a function and you add something liek this for example, ball:touch or ball:tap, are the touch or tap extensions so you can have more than one function specifically for different things but for the same variable?

and 2. What is a runtime event listener used for? [import]uid: 122076 topic_id: 22575 reply_id: 322575[/import]

To answer your second question – a runtime event listener focuses on whatever it is told to listen to, and executes the code many times per second to check for changes in the program.

[import]uid: 7116 topic_id: 22575 reply_id: 89985[/import]

@brandonbuffa2010 I’m not sure I fully understand your first question.

But lets assume you have a display object called ball and you want it to respond to different events, like, touch, tap etc. You define a function for that specific event. Lua gives you different ways to do things. My preferred way is like this:

[code]
local ball = display.newImage(“ball.png”)
ball.x = 100
ball.y = 100

local function ballTouchHandler(event)
– code you want to run when the ball is touched
end

ball:addEventListener(“tap”,ballTouchHandler)

Of course you really can’t put a touch listener and a tap listener on the same object since they both watch for the item to be touched. But you can put other listeners like “collision” and such using the same mechanisim.

As for the last question, think of “Runtime” is the master program. These listeners are not attached to any specific object but rather to the system as a whole. This could include things that monitor system events like rotation, low memory and tilt actions. These events only fire when the specific events happen if at all. The user may not ever rotate the device for instance.

One of the Runtime events is something called “enterFrame”. Your app runs at either 30 frames per second or 60 frames per second (30 is the default), so every 1/30th (or 1/60th) of a second Corona updates the display. Prior to the screen update, if there is an enterFrame event defined, it will run that code first. This is frequently how we have a “Game Loop” that runs continuously instead of waiting on some user interaction to do things. [import]uid: 19626 topic_id: 22575 reply_id: 90015[/import]