开发者

How to handle a drag gesture in corona

开发者 https://www.devze.com 2023-03-01 17:32 出处:网络
I\'m new to corona, 开发者_C百科and was wondering how to create a drag gesture in corona?First off use a \"touch\" event listener and not \"tap.\" Tap only responds when you lift your finger back up,

I'm new to corona, 开发者_C百科and was wondering how to create a drag gesture in corona?


First off use a "touch" event listener and not "tap." Tap only responds when you lift your finger back up, but touch responds to both putting down and picking up your finger.

The touch event has separate phases for "began" and "ended" that you can use to get the beginning and end of the drag gesture:

http://developer.anscamobile.com/reference/index/eventphase-0

Also, if you want to respond to touches anywhere onscreen (rather than just on one object) then add the listener to Runtime:

Runtime:addEventListener("touch", onTouch)


function drawLine( event )
  if(event.phase == "ended") then
    line = display.newLine(event.xStart, event.yStart, event.x, event.y)
    line:setColor(255,0,0)
    line.width = 5
  end
end
Runtime:addEventListener("touch", drawLine)

will produce a line between the start and end of the drag.

source: http://developer.anscamobile.com/reference/index/eventxstart

(should search before asking)

0

精彩评论

暂无评论...
验证码 换一张
取 消