Getting Started - dmc-gestures

Ease your way into dmc-gestures.

Installation

For installation instructions see !! file not found !!.

General Usage

The touch object can be used as either the controller which just accepts touch events or additionally as the object being controlled. The difference really depends on your touch handler and to which object it applies a gesture's values, either the original view or a separate object.

There are examples of both found in the repo directory examples.

Simple gesture handling

This example just displays the gesture event:

-- setup some constants to make placement easier
local W, H = display.contentWidth, display.contentHeight
local H_CENTER, V_CENTER = W*0.5, H*0.5

-- import the gesture library
local Gesture = require 'dmc_corona.dmc_gestures'

-- setup our touch area for the gesture
local view = display.newRect( H_CENTER, V_CENTER+40, V_CENTER, V_CENTER )

-- create our handler, looking for event GESTURE
local function gestureEvent_handler( event )
    -- print( "gestureEvent_handler" )
    if event.type == event.target.GESTURE then
        "Gesture: "..tostring( event.gesture )
    end
end

-- add a tap gesture, using the defaults (single tap, single touch)
local tap = Gesture.newTapGesture( view )
tap:addEventListener( tap.EVENT, gestureEvent_handler )

Stacking gestures

Gestures can also be "stacked" on a view to watch for more than one gesture.

This snippet is from the example gesture-multigesture-basic
view = display.newRect( H_CENTER, V_CENTER+40, V_CENTER, V_CENTER )
view:setFillColor( 0.3,0.3,0.3 )

-- create some gestures, link to touch area

-- pan gestures

pan = Gesture.newPanGesture( view, { touches=1, id="1 pan" } )
pan:addEventListener( pan.EVENT, gestureEvent_handler  )

pan = Gesture.newPanGesture( view, { touches=2, id="2 pan" } )
pan:addEventListener( pan.EVENT, gestureEvent_handler )

pan = Gesture.newPanGesture( view, { touches=3, id="3 pan" } )
pan:addEventListener( pan.EVENT, gestureEvent_handler )

-- tap gestures

tap = Gesture.newTapGesture( view, { id="1 tch 1 tap" }  )
tap:addEventListener( tap.EVENT, gestureEvent_handler )

tap = Gesture.newTapGesture( view, { touches=2, taps=2, id="2 tch 2 tap" } )
tap:addEventListener( tap.EVENT, gestureEvent_handler )

tap = Gesture.newTapGesture( view, { touches=3, taps=1, id="3 tch 1 tap" } )
tap:addEventListener( tap.EVENT, gestureEvent_handler )