I’ve been mulling over this for a week and am not sure what to do. This ONE problem has been the bane of my existence for the longest time.
I’m spawning E_bomb1 from this code at randomn points from the top of the screen. Once it reaches the bottom it fires off E_hit, which triggers removeSelf to remove it from the sim.
I also applied removeSelf to a touch event, so that if it is touched it also disappears.
What happens is when one E_bomb1 is touched and removeSelf any of the other E_bomb1s that are on the screen at that moment freeze their transition downward. The E_bomb1s that spawn afterwards continue to do fine, it’s just these guys that were already in play when touch was triggered screw up.
I’ve read enough to know that apparently I might be applying this removeSelf to every instance of E_bomb1 when touch is triggered and thus the other E_bomb1s in play lose their direction and stop when touch is triggered. But I can’t for the life of me find out how I can make it so that only the E_bomb1 that was touched is effected.
Here is my code:
local \_H = display.contentHeight;
local \_W = display.contentWidth;
--Bomb Code Begin
--Enemy Bomb1 spawn
--Take note that "local" makes the E\_bomb variable local to one instant of it, as opposed to without local, which makes it apply
--to all variables.
function E\_bomb1Spawn()
local E\_bomb1
E\_bomb1 = display.newImage("E\_bomb1.png")
E\_bomb1.x = math.random( \_W )
E\_bomb1.y = -10
E\_bomb1.xScale = 1
E\_bomb1.yScale = 1
--Adding the E\_bomb1.height/2 covers the other half of the height when it touches the bottom.
transition.to( E\_bomb1, { time=3000, y= (display.contentHeight - display.screenOriginY) + E\_bomb1.height/2 , onComplete=function() E\_hit(E\_bomb1) end })
--\*\*\*This is the part I'm having trouble with, when E\_hit happens, it's fine. Once I touch, the E\_bomb1s on screen other than
--\*\*\*the one touched ceases to animate.
function E\_bomb1:touch(e)
E\_bomb1:removeSelf()
end
E\_bomb1:addEventListener("touch", E\_bomb1);
function E\_hit(E\_bomb1)
E\_bomb1:removeSelf();
end
end
E\_bomb1Spawn()
--SpawnTimer
E\_bomb1Spawner = timer.performWithDelay(1000, E\_bomb1Spawn, -1);
--Bomb Code End
I searched everywhere for a solution, probably annoyed people enough in the chatroom, and cannot find a method. Can someone PLEASE just sit me down and tell me the proper way to do it? [import]uid: 44572 topic_id: 8306 reply_id: 308306[/import]
[import]uid: 44572 topic_id: 8306 reply_id: 29829[/import]