Spawning instances of a sprite or display object

Hey gang,

I’ve searched up and down, and can’t seem to find the perfect answer to my question. Hopefully y’all can help me out. :slight_smile:

I have multiple targets I’m shooting, and when the bullet hits the target, I want to spawn a little squib display object, that will soon be a sprite. Unfortunately though, the squib graphic just seems to jump from target to target after the bullet hit. In other words, I am defining one object/sprite in my code, and want to have multiple on screen at one tim in different stages of animating. I know this HAS to be possible, but I just can’t seem to get it working like I expect. Any help would be awesome.

Thanks!
–Kevin [import]uid: 70550 topic_id: 30424 reply_id: 330424[/import]

If you want multiple objects on screen at same time, you have to create multiple objects… [import]uid: 160496 topic_id: 30424 reply_id: 121886[/import]

You can create multiple instances of the same sprite and then start them playing with slight delays so that they are staggered, if that is what you are looking for? [import]uid: 52491 topic_id: 30424 reply_id: 121952[/import]

Hey Peach and Mike,

Yep, that’s exactly what I’m looking for. Right now, when a bullet hits a target, it spawns a sprite. If another bullet hits soon after, the sprite actually moves to the new spot instantaneously. I’m wanting to spawn instances and have them destroyed right after, allowing multiple to be on screen at the same time.

Are there any good examples of this? I feel like this has to be sooo basic, and I’m not seeing the forest for the trees.

Thanks!
–Kev [import]uid: 70550 topic_id: 30424 reply_id: 122380[/import]

Ok, the following code should (I think, Peach, correct me if I’m wrong) spawn a rectangle centered on x,y (replace it with creating a sprite in your code), move it horizontally for a second, then destroy it

local R=display.newRect(0,0,20,20); R.x=x; R.y=y transition.to(R,{time=1000, delta=true, x=100, onComplete=function() display.remove(R); R=nil; end}) [import]uid: 160496 topic_id: 30424 reply_id: 122384[/import]

If you want multiple objects on screen at same time, you have to create multiple objects… [import]uid: 160496 topic_id: 30424 reply_id: 121886[/import]

You can create multiple instances of the same sprite and then start them playing with slight delays so that they are staggered, if that is what you are looking for? [import]uid: 52491 topic_id: 30424 reply_id: 121952[/import]

Hey Peach and Mike,

Yep, that’s exactly what I’m looking for. Right now, when a bullet hits a target, it spawns a sprite. If another bullet hits soon after, the sprite actually moves to the new spot instantaneously. I’m wanting to spawn instances and have them destroyed right after, allowing multiple to be on screen at the same time.

Are there any good examples of this? I feel like this has to be sooo basic, and I’m not seeing the forest for the trees.

Thanks!
–Kev [import]uid: 70550 topic_id: 30424 reply_id: 122380[/import]

Ok, the following code should (I think, Peach, correct me if I’m wrong) spawn a rectangle centered on x,y (replace it with creating a sprite in your code), move it horizontally for a second, then destroy it

local R=display.newRect(0,0,20,20); R.x=x; R.y=y transition.to(R,{time=1000, delta=true, x=100, onComplete=function() display.remove(R); R=nil; end}) [import]uid: 160496 topic_id: 30424 reply_id: 122384[/import]