0
local function removeTrumps(obj)
obj:removeSelf()
trumps=trumps-1
--[[local thisTrump=myTrump.id
display.remove(myTrump[thisTrump])
myTrump[thisTrump]=nil
table.remove(myTrump,thisTrump)]]--
if (timeLeft~=false) then
if(trumps==0) then
timer.cancel(gameTimer)
gameOver("winner")
elseif(trumps<=40) then
gameOver("notbad")
elseif(trumps>=31) then
gameOver("loser")
end
end
end
local function startGame()
myTrump[#myTrump+1]=display.newImageRect("tp.png",25,25)
myTrump[#myTrump].x=Random(50,_W-50)
myTrump[#myTrump].y=(_H+10)
myTrump[#myTrump].id=#myTrump
physics.addBody(myTrump[#myTrump],"dynamic", {density=.1, friction=0, bounce=.9, radius=9})
--TOUCH FUNCTION FIX IT
function onTouch(event)
if(timeLeft~=false) then
if (playerReady==true) then
if(event.phase=="ended") then
removeTrumps(self)
end
end
end
end
--if i put onTouch then removetrumps is ? if i leave it as #myTrump it just doenst recognize the touch
myTrump[#myTrump]:addEventListener("touch", onTouch)
trumps=trumps+1
if(trumps==numTrumps) then
gameTimer=timer.performWithDelay(1000,countDown,totalTime)
else
playerReady=false
end
end
여기 내 문제가 있습니다. 나는 이벤트 리스너를 테이블 객체 #myTrump
에 올바르게 설정하는 방법을 모르며 이미지를 클릭하면 이미지가 사라지지만 올바르게 작동하지 않습니다. 지금은 obj (removeTrumps
함수에서)가 0 값인 것에 대해 이야기하고 있습니다. 이 문제를 어떻게 해결할 수 있습니까? 개체가 사라지지 않습니다.코로나의 표 객체에 이벤트 리스너 추가