Cover by Daniel Williams

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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 = event.target if event.phase == "began" then elseif t.isFocus then if "moved" == event.phase then elseif "ended" == event.phase ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required