You are previewing Corona SDK Application Design.

Corona SDK Application Design

Cover of Corona SDK Application Design by Daniel Williams Published by Packt Publishing

Dragging-and-dropping display objects

Now we are going to set up the core functionality for our app—dragging-and-dropping display objects. To allow our players to drag-and-drop display objects, we have to set up a function that will allow them to grab an object and drag it around the screen. We can accomplish this by attaching an event listener to the object with the function that handles the dragging. However, before we can attach the event listener, we need to set up a function dedicated to this purpose.

A sample drag function with the associated object event listener would be as follows:

local function onDrag(event) local t = if event.phase == "began" then elseif t.isFocus then if "moved" == event.phase then elseif "ended" == event.phase ...

The best content for your career. Discover unlimited learning on demand for around $1/day.