好吧我的问题是Corona SDK给我错误,当我尝试在一段时间后删除爆炸对象时,尝试调用方法'removeSelf()'(一个零值)。我尝试了很多不同的解决方案,但没有一个有效。我是Corona SDK的新手,所以我需要帮助。这是带有问题的代码:
local function addExplosion(x, y)
local explosion = display.newImage("Explosion.png", x, y)
physics.addBody(explosion, "static")
timer.performWithDelay(1000, function(self)
self:removeSelf()
end, 1)
end
local function onCollision(event)
if (event.phase == "began") then
if(event.object1.hasCollided == false and event.object2.hasCollided == false and event.object1.y > 50) then
local explosionSound = audio.loadSound("Explosion.ogg")
local explosionChannel = audio.play(explosionSound)
local collisionX = (event.object1.x + event.object2.x) * 0.5
local collisionY = (event.object1.y + event.object2.y) * 0.5
event.object1.hasCollided = true
event.object2.hasCollided = true
event.object1:removeSelf()
event.object2:removeSelf()
addExplosion(collisionX, collisionY)
score = score - 5
scoreText.text = score
end
end
end
local function addBomb()
local startX = math.random(display.contentWidth * 0.1, display.contentWidth * 0.9)
local bomb = display.newImage("bomb.png", startX, -10)
physics.addBody(bomb, "dynamic")
bomb.hasCollided = false
Runtime:addEventListener("enterFrame", bomb)
bomb:addEventListener("touch", bombTouched)
end
local function addBalloon()
local startX = math.random(display.contentWidth * 0.1, display.contentWidth * 0.9)
local balloon = display.newImage("red_balloon.png", startX, display.contentHeight + 50)
physics.addBody(balloon, "dynamic")
balloon.gravityScale = -0.5
balloon.enterFrame = offscreen
balloon.hasCollided = false
Runtime:addEventListener("enterFrame", balloon)
Runtime:addEventListener("collision", onCollision)
end
答案 0 :(得分:0)
你无法调用self:removeSelf()因为它是零。 我想你想要删除你的爆炸对象?
local function addExplosion(x, y)
local explosion = display.newImage("Explosion.png", x, y)
physics.addBody(explosion, "static")
timer.performWithDelay(1000, function(self)
self:removeSelf()
end, 1)
end
想想这个位置的自我(打印它以获得更多信息)