Ive been trying for a couple weeks now to remove the instance of my projectile without it affecting all the other instances of said projectile and cant seem to figure it out… Basically when the bullet hits the target, I want that instance of the bullet to fade out, and be removed, without affecting any other bullets in the stage.
– this code doesnt really work at all, but is a general template of how I was trying to accomplish this. Thanks in advance to anyone who might shed some light on this for me!
[code]
local bullets = display.newGroup()
local n = 1
local function fireBullet(e)
if e.phase == “began” then
bullet = display.newImage(“bullet.png”)
bullet.x, bullet.y = e.x, e.y
bullets:insert(bullet)
local function moveBullet()
BulletTrans = transition.to( bullet[n], { time=2500, alpha=1, x=(1000), y=(e.y),})
end
moveBullet()
end
end
Runtime:addEventListener(“touch”, fireBullet)
local function removeBullet()
bullets[n].removeSelf()
end
local function stopBullet()
transition.cancel(BulletTrans)
transition.to(bullet, {time = 750, alpha = 0})
removeBulletTimer = timer.performWithDelay(500, removeBullet, 1)
end
local function onLocalCollision(self, event)
if (event.phase == “began”) then
timer.performWithDelay(0, stopBullet, 1)
end
target.collision = onLocalCollision
target:addEventListener( “collision”, target )
[import]uid: 28912 topic_id: 7424 reply_id: 307424[/import]