메뉴 건너뛰기

창작에 관련된 질문이나 간단한 팁, 예제를 올리는 곳

-- 안드로이드/iOS 등등의 터치스크린 입력을 받는 기기에서는 총 3가지의 콜백 함수를 사용한다:

-- love.touchpressed / love.touchmoved / love.touchreleased

-- 다만 위 3가지 함수는 마우스 클릭으로는 발생하지 않으므로 추가적인 처리가 필요하다.


-- 아래의 코드는 터치 입력을 touches{} 테이블에 저장한다.

-- touches[id] = {x, y, 눌린 시간}

-- 새로운 테이블 키를 추가하는 식으로 여러가지 정보(맨 처음에 눌린 위치 등)를 추가적으로 처리할 수 있다. 


local touches = {}


function love.load()

    count = 0

end


function love.draw()

local k, v

for k, v in pairs(touches) do

love.graphics.print(tostring(k) .. ":" .. math.floor(v[1]) .. ":" .. math.floor(v[2]) .. ":".. math.floor(v[3]), v[1], v[2])

end

love.graphics.print(count, 0, 0)

end


function love.touchpressed( id, x, y, dx, dy, pressure )

touches[id] = {x, y, 0}

count = count + 1

end


function love.touchmoved( id, x, y, dx, dy, pressure )

if touches[id] ~= nil then

touches[id][1] = x

touches[id][2] = y

end

end


function love.touchreleased( id, x, y, dx, dy, pressure )

touches[id] = nil

count = count - 1

end


function love.mousepressed( x, y, button, istouch, presses )

if istouch == false then 

love.touchpressed( "mouse", x, y, 0, 0, 1 )

end

end


function love.mousemoved( x, y, dx, dy, istouch )

if istouch == false then

if love.mouse.isDown(1) then

love.touchmoved( "mouse", x, y, dx, dy, 1 )

end

end

end


function love.mousereleased( x, y, button, istouch, presses )

if istouch == false then

love.touchreleased( "mouse", x, y, 0, 0, 0)

end

end


function love.update(dt)

-- 눌린 시간 갱신

local k, v

for k, v in pairs(touches) do

v[3] = v[3] + dt

end

end


제스처를 인식하는 기능 같은 건 없으므로

핀치 줌, 스와이프, 더블탭, 롱프레스 등등의 이벤트를 처리하고 싶으면 직접 인식하는 코드를 짜야 합니다.

분류 :
조회 수 :
20
등록일 :
2020.11.12
00:38:39 (*.47.15.167)
엮인글 :
게시글 주소 :
https://hondoom.com/zbxe/index.php?mid=study&document_srl=818623
List of Articles