2016-06-17 8 views
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

これを変更してみますremoveTrumps(self)removeTrumps(event.target)です。もう一つは、booleanを値trueまたはfalseと比較する必要はありません。

if timeLeft then --if (timeLeft ~= false) then "not false is true" 
    if playerReady then --if (playerReady == true) then 
     --some code here 
    end 
end 
関連する問題