display:touch()

Type    

user method of Display class

  [gd]

Overview

User-defined function

[bgl

Return value



See also    

Display class



Overview 


The onTouch() method of a Display object can be defined.

This method handles touch events and is called when the events are occurred.


Syntax


function dispobj:onTouch(e)

    …

    …

end


Here, dispobj is a Display object such as image or shapes. The argument e is a table that has the following fields.


        • phase : (string) this has four cases as follows.

                • 'begin'  : touch began

                • 'move'  : touch point is moving.

                • 'end'     : touch ended

                • 'cancel' : touch cancelled

        • x     : the x-coordinates of touch point

        • y     : the y-coordinates of touch point

        • dx   : the deviations of x coordinates at 'move' phase.  At 'begin' phase, it is zero.

        • dy   : the deviations of y coordinates at 'move' phase. At 'begin' phase, it is zero.

        • id    : touch id (in case of multiple touches, this distinguishes between them)


Examples

 


local moon = Image('moon.png')

function moon:onTouch(e)

    if e.phase=='begin' then

        self:setScale(1.2):setDrot(2)

    elseif e.phase == 'move' then

        local tx = self:getX()+e.dx

        local ty = self:getY()+e.dy

        self:setXY(tx,ty)

    elseif e.phase=='end' or e.phase=='cancel' then

        self:setScale(1):setDrot(0)

    end

end


댓글 없음:

댓글 쓰기