在電暈觸摸聽衆你有3個狀態:
function listener(event)
if event.phase == "began" then
-- in the 1st tap the phase will be "began"
elseif event.phase == "moved" then
-- after began phase when the listener will be called with moved phase,like touched coordinates
elseif event.phase == "ended" then
--when the touch will end
end
end
nextButton:addEventListener("touch", listener)
- [[ 這是對圖像的簡單的觸摸監聽器,自制按鈕等,順便說一句,當你需要你要跟按鈕,使用究竟是什麼做的這個http://developer.coronalabs.com/code/enhanced-ui-library-uilua]
-- example for usage
local ui = require "ui" -- copy the ui.lua to your apps root directory
yourButton = ui.newButton{
defaultSrc = "menu/icon-back.png",--unpressed state image
x=85,
y=display.contentHeight-50,
defaultX = 110,
defaultY =80,
offset=-5,
overSrc = "menu/icon-back-2.png",--pressed state image
overX = 110,
overY = 80,
onEvent = buttonhandler,
id = "yourBtnId" -- what you want
}
local function buttonhandler(event)
if event.phase == "release" then
--if you have more buttons handle it whit they id-s
if event.id == "yourBtnId" then
-- when your button was finally released (like in 1st example ended, but this will be called only if the release target is your button)
end
end
end