[!gitHub-download-button.png|align=right!|https://github.com/dmccuskey/DMC-Corona-Library/tree/dmc_touch-new]

dmc_multitouch-on-branch
Though dmc-multitouch is already in use by other developers, it hasn't officially been released yet. so, in order to find it in the github repo, you will need to switch to its development branch. the icon to the right is already linked to that branch. Happy Coding ! -- dmc

Table of Contents

{toc:style=disc|indent=20px|minLevel=2|exclude=Table of Contents|printable=false}

Import

Import the library module like so:

{code:language=none|title=Import DMC Multitouch} local MultiTouch = require( "dmc_multitouch" )



## Overview

You layer on the functionality desired by calling the following function *_one or more times_*:



{code:language=none}
MultiTouch.activate( object, action, touch [, params] )

|| Parameter || Notes || | object | corona display object \ \ this is the Corona display object to be controlled by the touch interface | | action | "move", "rotate", "scale" (string) \ \ action is a string defining the behavior to add to the object | | touch | "single", "multi", { "single", "multi" } (string or table) \ \ touch defines how the behavior is controlled, either with a single touch or with a multi-touch gesture. a table can be used to define the action if it's to be controlled by both types of touch. | | params | { } (table) \ \ params is an optional parameter which contains properties used to constrain the behavior of the action. for example, the action "move" might have an upper bounds in the y-axis which movement cannot pass. \ \ { yBounds = { 120, nil } } |

Most behaviors can be added at the same time on an object except for a few certain cases. As you'll see in the following chart, some of the single-touch actions are not compatible. for example, starting on the left column, say i wanted to have the action single-touch Move ( M(1) ) added to my object. as i go along the row to the right, i can see that single-touch Rotate ( R(1) ) and single-touch Scale ( S(1) ) are not compatible.

|| || M(1) || M( x ) || R(1) || R( x ) || S(1) || S( x ) || | M(1) | — | !check.png|align=center! | !error.png|align=center! | !check.png|align=center! | !error.png|align=center! | !check.png|align=center! | | M( x ) | !check.png|align=center! | — | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | | R(1) | !error.png|align=center! | !check.png|align=center! | — | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | | R( x ) | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | — | !check.png|align=center! | !check.png|align=center! | | S(1) | !error.png|align=center! | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | — | !check.png|align=center! | | S( x ) | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | !check.png|align=center! | — |

Example

Here's an example of applying several behaviors to a single object {code:language=none|title=Example|linenumbers=true}-- setup object local o = display.newRect( 0, 0, 380, 380 ) o:setFillColor(255,255,255) o.x = 0 ; o.y = 0

-- layer on multitouch actions MultiTouch.activate( o, "scale", 'multi' ) MultiTouch.activate( o, "rotate", {'single','multi'} ); MultiTouch.activate( o, "move", {'multi'} );

--[[ object to be scaled with only multi-touch, rotated with both single- or multi-touch, moved by only multi-touch --]] ```

Functions

move

MultiTouch.activate( obj, "move", touch [, params] )

The params parameter is a table which can have one one or more of the following properties. These properties are used to constrain scaling.

Here are the options: || Constraint Params || Notes || | xBounds | | | yBounds | | | constrainAngle | |

scale

MultiTouch.activate( obj, "scale", touch [, params] )

The params parameter is a table which can have one one or more of the following properties. These properties are used to constrain scaling.

Here are the options: || Constraint Params || Notes || | minScale | (number) \ lower limit for the scale of the object. | | maxScale | (number) \ upper limit for the scale of the object. |

rotate

MultiTouch.activate( obj, "rotate", touch [, params] )

The params parameter is a table which can have one one or more of the following properties. These properties are used to constrain scaling.

Here are the options: || Constraint Params || Notes || | minAngle | (number) \ lower limit for the angle of the object rotation. can be negative or positive. | | maxAngle | (number) \ upper limit for the angle of the object rotation. can be negative or positive. |

Event

any action will fire off events for movement. an event listener can be attached to the object to find out about the events. || property || note || | x | x coordinate of the object's current position | | y | y coordinate of the object's current position | | xDelta | change in x coordinate since the beginning of the new touch | | yDelta | change in y coordinate since the beginning of the new touch | | direction | "clockwise", "counter_clockwise", nil \ \ will be set on rotation, or nil | | angleDelta | change in angle since the beginning of the new touch | | distanceDelta | change in the distance from the beginning of the move to the current position \ \ pythagorean theorem -- sqrt( xDelta^2 + yDelta^2 ) |