I'm making a shooting game with solar 2d, everything was working fine but after some time I feel that the games frame rate is dropping, but I did steps to delete my laser when the task finishes
local function fireLaser()
audio.play( fire sound )
newLaser = display.newImageRect( mainGroup, objectSheet, 5, 14, 40 )
physics.addBody( newLaser, "dynamic", { isSensor=true } )
newLaser.isBullet = true
newLaser.myName = "laser"
newLaser.x = ship.x
newLaser.y = ship.y
newLaser:toBack()
transition.to( newLaser, { y=400, time=500,
onComplete = function()display.remove( newLaser ) end
} )
end
I think what is happening, that onComplete calls the display.remove( newLaser ) after 600ms but the function again called but in less than 600ms , say 400ms, so display.remove( newLaser ) dump the first object which is called on first clicked and remove the second one or say latest one, but if the player continuously clicking the fire laser button, and each click has a difference of less than 600 ms, then nothing would be removed. Please Help me as soon as possible.
If you are only using
newLaserinside offireLaseryou should define it as alocalvariable.This will seem like a insignificant change, but when you do
you are creating a enclosed function.
This does not work when
newLaserisglobalbecause each call tofireLaseris acting on the sameglobalvariable ofnewLaserrather than a uniquelocalvariable.