我有石头和苹果等物体连续下落,现在我需要在触摸时消除苹果并得到我触摸的苹果数量....请帮助......我对CORONA全新......这是我的代码:
function newApples()    
rand = math.random( 100 )
if (rand < 60) then
    j = display.newImage("s1.png");
    j.x = 60 + math.random( 160 )
    j.y = -100
    physics.addBody( j, { density=0.9, friction=0.3, bounce=0.3} )
elseif (rand < 80) then
    j = display.newImage("s2.png");
    j.x = 60 + math.random( 160 )
    j.y = -100
    physics.addBody( j, { density=1.4, friction=0.3, bounce=0.2} )
else
    apple = display.newImage("apple1.png");
    apple.x = 60 + math.random( 160 )
    apple.y = -100
    physics.addBody( apple, { density=0.3, friction=0.2, bounce=0.5} )
    apple.name = "apple"
end 
end
local dropApples = timer.performWithDelay( 500, newApples, -1 )
function onTouch(event)
  print("this")
  event:removeSelf()
end
apple:addEventListener("tap",onTouch)
Run Code Online (Sandbox Code Playgroud)
    我认为此代码可以帮助您:
local physics = require("physics")
physics.start()
local appletouchcount=0
function newApples()    
rand = math.random( 100 )
if (rand < 60) then
j = display.newImage("s1.png");
j.x = 60 + math.random( 160 )
j.y = -100
elseif (rand < 80) then
j = display.newImage("s2.png");
j.x = 60 + math.random( 160 )
j.y = -100
physics.addBody( j, { density=1.4, friction=0.3, bounce=0.2} )
else
apple = display.newImage("apple1.png");
apple.x = 60 + math.random( 160 )
apple.y = -100
physics.addBody( apple, { density=0.3, friction=0.2, bounce=0.5} )
apple.name = "apple"
function onTouch(event)
appletouchcount= appletouchcount+1
 print("this")
event.target:removeSelf()
print("total"..appletouchcount)
end
apple:addEventListener("touch",onTouch)
end 
end
local dropApples = timer.performWithDelay( 500, newApples, -1 )
Run Code Online (Sandbox Code Playgroud)
appletouchcount是你触摸过的苹果数量.