[Resolved] Need help with sprite instance removal

Well, i want to shoot lazers. All works fine but but i cant get to remove the lazers from the screen after they’ve been shot.
Lazers are sprite instances. I only want to remove the one which has reached its destination, not the full sprite sheet using dispose()!. My code can explain the rest. I’d really much appreciate if i can get help. Thanx in advance.

local sprite = require “sprite”
local button = display.newImage (“fire.png”) --shoot lazers button
button.x = 250
button.y = 250
local blastersheet = sprite.newSpriteSheet(“blaster.png”, 64, 25)
local blasterset = sprite.newSpriteSet (blastersheet, 1, 11)
sprite.add (blasterset, “fireA”, 1, 11, 600, 3)

local remover = function (obj)
si:dispose()
blastersheet = sprite.newSpriteSheet(“blaster.png”, 64, 25)
blasterset = sprite.newSpriteSet (blastersheet, 1, 11)
sprite.add (blasterset, “fireA”, 1, 11, 600, 3)
end

local function down ()
local si = sprite.newSprite (blasterset)
si.x = 20
si.y = 20
si:prepare(“fireA”)
si:play(“fireA”)
transition.to(si,{delay = 1, time = 2000, x = si.x + 250, onComplete = remover})
end
button:addEventListener(“touch”, down)

[import]uid: 176335 topic_id: 32240 reply_id: 332240[/import]

@sherrulz,

Try this change:

  
local remover = function( obj ) -- Use the reference 'obj', not 'si'  
  
 print("In remover()") -- Just to show that is being called. (Prints in console)  
  
 -- 1. You need to use the 'obj' referene, not 'si'  
 -- 2. I think you meant removeSelf(), not dispose  
 --si:dispose()   
 obj:removeSelf()  
  
 blastersheet = sprite.newSpriteSheet("blaster.png", 64, 25)  
 blasterset = sprite.newSpriteSet (blastersheet, 1, 11)  
 sprite.add (blasterset, "fireA", 1, 11, 600, 3)  
end  

Also, one small request, please use the < code > < / code > brackets for your next code question. It will make it easier for folks to help.

Cheers,
Ed [import]uid: 110228 topic_id: 32240 reply_id: 128317[/import]

THANKYOU!
And yes, i didnt see that code bracket, first time.
Cheers!
[import]uid: 176335 topic_id: 32240 reply_id: 128318[/import]

@sherrulz,

Try this change:

  
local remover = function( obj ) -- Use the reference 'obj', not 'si'  
  
 print("In remover()") -- Just to show that is being called. (Prints in console)  
  
 -- 1. You need to use the 'obj' referene, not 'si'  
 -- 2. I think you meant removeSelf(), not dispose  
 --si:dispose()   
 obj:removeSelf()  
  
 blastersheet = sprite.newSpriteSheet("blaster.png", 64, 25)  
 blasterset = sprite.newSpriteSet (blastersheet, 1, 11)  
 sprite.add (blasterset, "fireA", 1, 11, 600, 3)  
end  

Also, one small request, please use the < code > < / code > brackets for your next code question. It will make it easier for folks to help.

Cheers,
Ed [import]uid: 110228 topic_id: 32240 reply_id: 128317[/import]

THANKYOU!
And yes, i didnt see that code bracket, first time.
Cheers!
[import]uid: 176335 topic_id: 32240 reply_id: 128318[/import]