2013-07-23 2 views
0

[SOLVED] 찾아 주셔서 감사합니다.하지만 알아 냈습니다. 일부 if 조건에서 return true 문을 중첩 해제해야했습니다.루아 코로나 SDK 충돌 이벤트 리스너

저는 이번 주에 Lua를 배우기 시작했고, 코로나 SDK를 사용하여 2D 측면 스크롤러 게임을 프로그래밍하기 시작했습니다. 이 게임에서, 플레이어의 캐릭터는 가상 게임 패드처럼 화면에 표시된 버튼을 눌러 움직입니다. 이 버튼은 그러나, 문제는 그때 탭이 등록 될 때마다 플레이어에서 발사체를 발사하기 위해 촬영() 함수를 호출하는

Runtime:addEventListener("tap", onScreenTap) 

이벤트 리스너를 가지고있다, 완벽하게 작동합니다. 그 결과 움직이는 버튼 중 하나에서 손을 뗄 때마다 발사체가 발사됩니다.

이동 키 중 하나를 끝내면 촬영 기능이 호출되지 않게 할 수 있습니까? 나는

display.getCurrentStage:setFocus() 

또한 운동 기능의 끝에서

return true 

을 넣어하지만 아무것도 작동하는 것 같다없는 시도했다.

답변

2

모든 기본 기능은 모든 터치 기능에 사용할 수 있습니다. 단일 기능으로 터치 이벤트를 결합하면 문제가 해결 될 수 있습니다.

function inBounds(event) 
    local bounds = event.target.contentBounds 
    if event.x > bounds.xMin and event.x < bounds.xMax and event.y > bounds.yMin and event.y < bounds.yMax then 
     return true 
    end 
    return false 
end 


function touchHandler(event) 
    if event.phase == "began" then 
     -- Do stuff here -- 
     display.getCurrentStage():setFocus(event.target) 
     event.target.isFocus=true 
    elseif event.target.isFocus == true then 
     if event.phase == "moved" then 
      if inBounds(event) then 
       -- Do stuff here -- 
      else 
       -- Do stuff here -- 
       display.getCurrentStage():setFocus(nil) 
       event.target.isFocus=false 
      end 
     elseif event.phase == "ended" then 
      -- Do stuff here -- 
      display.getCurrentStage():setFocus(nil) 
      event.target.isFocus=false 
     end 
    end 
    return true 
end 

그런데 런타임에 이것을 사용하려고하면 오류가 발생하고 오류가 발생합니다. 백그라운드에 이벤트 리스너를 추가하거나 일부 컨트롤 메카니즘을 넣을 수 있습니다.

if event.target then 
-- blah blah 
end 
+0

답장을 보내 주셔서 감사합니다.이 구문이 어떻게 도움이되는지를 알 수 있습니다. 그러나, 나는 가지고있는 문제를 해결했다. –

관련 문제