그래서 내가 onCollision 이벤트의 사용하여 게임을 좀하고 있어요 :시도
local function onCollision(event)
if event.phase == "began" and gameIsActive == true then
local obj1 = event.object1;
local obj2 = event.object2;
if obj1.name == "bill" then
if obj2.name == "rocks" then gameover()
elseif obj2.name == "" then
end
end
end
end
Runtime:addEventListener("collision", onCollision)
을하지만, 처음 예상대로 내가 코드가 작동하는 약간의 문제가 실행 시간이지만 게임을 다시 시작합니다.이 오류가 발생합니다.
File: game.lua
Line: 649
Attempt to call global 'gameover' (a table value)
stack traceback: game.lua:649: in function <game.lua:643> ?: in function <?:221>
649 = if obj2.name == "rocks" then gameover()
643 = local function onCollision(event)
어떤 생각일까요?
gameover 기능 :
function gameover()
rightTAP:removeEventListener("tap", movePLAYERr)
leftTAP:removeEventListener("tap", movePLAYERl)
timer.pause(spawnBits)
timer.pause(Rockspawner1)
timer.pause(tmrscore)
timer.pause(updateScoretimer)
timer.pause(spawnDinosControll)
audio.pause(drillingChannel)
drillbg.isVisible = false
scoreText.isVisible = false
Restartg = display.newText("Restart", 0, 0,nil, 20)
Restartg:setFillColor(0, 0, 0)
screenGroup:insert(Restartg)
Restartg.x= display.contentWidth/2
Restartg.y= display.contentHeight/2 + 160
Restartg:addEventListener("tap", RestartGame1)
end
질문에 gameover 기능을 추가 –