corona handson#3
TRANSCRIPT
ColonaLabs.com
Code Less, Play More ! with Corona SDK #3
CoronaSDK Ambassador 小野 哲生
13年3月8日金曜日
ColonaLabs.com
Corona SDK でのタッチイベント
三限目。。。キーンコーン♪
カーンコーン♪
13年3月8日金曜日
ColonaLabs.com
Corona SDK でのタッチイベント
• touch, multi touch( multi は実機解説 )
• drag ( オブジェクトのドラッグ )
• tap, swipe ( Table View のタッチ)
• pinch ( コード、iOS Simulator 解説 )
13年3月8日金曜日
ColonaLabs.com
• touch( タッチで図形描画 )
local function onTouch( event ) if(event.phase == "began") then
local rect = display.newRect(20, 20, 100, 100 )
endend
Runtime:addEventListener( "touch", onTouch )
Corona SDK でのタッチイベント
13年3月8日金曜日
ColonaLabs.com
• touch( 図形タッチで色変更 )
local rect = display.newRect(20, 20, 100, 100 )
local function changeRGB( event ) rect:setFillColor( 250, 130, 10 )
end
rect:addEventListener( "touch", changeRGB )
Corona SDK でのタッチイベント
13年3月8日金曜日
ColonaLabs.com
• multi touch_1
system.activate("multitouch")
local _W = display.contentWidthlocal _H = display.contentHeightlocal counter = 0
local txt1 = display.newText( " ", 0, 20, nil, 28 )txt.x = _W/2 ; txt.y = _H/2
Corona SDK でのタッチイベント
13年3月8日金曜日
ColonaLabs.com
• multi touch_2( _1の続き )
Corona SDK でのタッチイベント
local function onTouch( event )
if( event.phase == "began" ) thencounter = counter + 1if ( counter == 1 ) then
txt.text = "It's single touch !"elseif ( counter == 2 ) then
txt.text = "It's multi touch !"end
end13年3月8日金曜日
ColonaLabs.com
• multi touch_3( _2の続き )
Corona SDK でのタッチイベント
if( event.phase == "ended" ) thencounter = counter - 1if ( counter == 1 ) then
txt.text = "It's single touch !"elseif ( counter == 0 ) then
txt.text = " "end
endendRuntime:addEventListener("touch", onTouch)
13年3月8日金曜日
ColonaLabs.com
local rect = display.newRect(20, 20, 100, 100 )
local function moveRect( event ) local t = event.targetlocal phase = event.phaseif( "moved" == phase ) then
t.x = event.x; t.y = event.yend
endrect:addEventListener( "touch", moveRect )
• drag
Corona SDK でのタッチイベント
13年3月8日金曜日
ColonaLabs.com
• tap, swipe
Corona SDK でのタッチイベント
事前準備
• https://github.com/TetsuoOnoCoronaSDK-3_1
• 画像「mask.png」 を追加
13年3月8日金曜日
ColonaLabs.com
• tap, swipe_1
local widget = require "widget"local _W = display.contentWidth
local txt = display.newText( " ", 0, 400, nil, 28 )txt.x = _W/2
local list = widget.newTableView{top = 20, height = 366, maskFile = "mask.png"}
Corona SDK でのタッチイベント
13年3月8日金曜日
ColonaLabs.com
• tap, swipe_2( _1の続き )
Corona SDK でのタッチイベント
local function rowListener( event )
if( event.phase == "tap" )thentxt.text = "It's Tap !"
elseif( event.phase == "swipeLeft" )thentxt.text = "It's Swiped Left !"
elseif( event.phase == "swipeRight" )thentxt.text = "It's Swiped Right !"
end13年3月8日金曜日
ColonaLabs.com
• tap, swipe_3( _2の続き )
Corona SDK でのタッチイベント
for i = 1, 100 dolocal rowHeightlocal listener = rowListenerlist:insertRow{
height = rowHeight,rowColor = rowColor,isCategory = isCategory,onRender = onRowRender,listener = listener }
end13年3月8日金曜日
ColonaLabs.com
• pinch
Corona SDK でのタッチイベント
解説のみ
• https://github.com/TetsuoOnoCoronaSDK-3_2
• main.lua コード解説• iOS Simulator でのピンチ動作
13年3月8日金曜日
ColonaLabs.com
Corona SDK #3 まとめ
• touch, multi touch( multi は実機解説 )
• drag ( オブジェクトのドラッグ )
• tap, swipe ( Table View のタッチ)
• pinch ( コード、iOS Simulator 解説 )
13年3月8日金曜日
ColonaLabs.com
お疲れさまでした。。。
#4へ つづく。。。
13年3月8日金曜日