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
Also hier ist mein Problem. Ich weiß nicht, wie man den onTouch
Event-Listener richtig auf das Tabellenobjekt #myTrump
setzt, und ich versuche es so zu machen, wenn man auf das Bild klickt, verschwindet es, aber es funktioniert nicht richtig. Die Art, wie es jetzt ist, spricht davon, obj (in der removeTrumps
-Funktion) ein Nullwert ist. Wie behebe ich das? Die Objekte verschwinden nicht.Hinzufügen von Ereignis-Listener zum Tabellenobjekt in Corona