I need help programming bullets!

Below is skeleton code for bullets/various other things that are created in multiples

var i:Number = 0;
var goTime:Boolean = true;

function newThingy(){
	if(goTime == true){
		attachMovie("thingy", "thingy" +i, i);
		thingy = _root["thingy" +i];
		thingy._x = 100;
		thingy._y = 200;
		goTime = false;
		i++;
	}
	thingy._x += 5;
	if(thingy._x > 550){
		removeMovieClip(this);
	}
}
function timer(){
	goTime = true;
}

setInterval(timer, 500);
this.onEnterFrame = function(){
	newThingy();
}

Ok, so whenever I run this code, the “thingy” that was created last stops wherever it is when the next “thingy” is created. How do I make them behave like I want them to, and go all the way to the end of the screen?

this is AS2 yes?
Basically what you want to do is have a copy of the bullet off screen which you duplicate to make new bullets.

An example of how to do this: (the attached file)
I made this ages ago so its not exactly the most clearly written code, PM if you have any further questions.

Hope this helps. :smiley:

It works beautifully! Thanks a ton :smiley:

The crucial point isn’t whether you use attachMovie or duplicateMovie. The crucial point is that there is one and only one thingy.
Consider this:


function newThingy(){
if(goTime == true){
attachMovie("thingy", "thingy" +i, i);
thingy = _root["thingy" +i];
thingy._x = 100;
thingy._y = 200;
goTime = false;
i++;
thingy.onEnterFrame= function () {
this._x += 5;
if(this._x > 550){
removeMovieClip(this);
}

}
}
}

Another solution would be to push thingy to an array, and then every frame, you would loop through the array and move each item in the array.

Thanks everyone! The code itself is working fine. Now I just have to figure out why it’s not firing properly :frowning: