local enemy
local enemyNumber
local function choose1()
local choose = rnd(1, 2)
-- If satsen
if(choose == 1) then
if(ballSizeEnemy \<= 8) then
enemyNumber = 1
end
enemy = display.newImage(""..enemyNumber..".png", rnd(0, 480), -140)
localGroup:insert(enemy)
worldGroup:insert(enemy)
-- Radie på enemy
if(enemyNumber == 1) then
enemySize = 4
end
-- Fysik
physics.addBody(enemy, { density=1.0, friction=0.3, bounce=0,
radius=enemySize, isSensor=true })
if(enemyNumber == 1) then
enemy:applyForce(0, rnd(3, 7), 0, 0)
end
-- Opacy
enemy.alpha = 0.7
-- Lägg in i grupp
enemyGroup:insert(enemy)
-- Ingen rotation
enemy.isFixedRotation = true
-- Is Collideable
enemy.isCollideable = true
local function enemyCollision(self, event)
if(event.phase == "began" and event.other.class == "enemyCleaner") then
self:removeSelf()
self = nil
elseif(event.phase == "began" and event.other.class == "eastWall") then
self:removeSelf()
self = nil
end
end
enemy.collision = enemyCollision
enemy:addEventListener("collision", enemy)
-- Slut på If satsen
end
return true
end
local enemyTimer = performAfterDelay(0.3, choose1, 0, true)
Ok, so I’ve got this code above. Everything works great in the latest official build (268), but now when I tried this same code in the latest build (312) the game crashes. It crashes every time enemy collides with either enemyCleaner or eastWall. I remember someone long ago telling me that removing physical objects upon collision would cause crashes, but the code works great in build 268?
Thanks in advance, [import]uid: 30185 topic_id: 7727 reply_id: 307727[/import]