Skip to main content
Participant
January 8, 2009
Question

My bullets dont work in my game >.<

  • January 8, 2009
  • 2 replies
  • 317 views
I have a ship mc on the stage called "hero" and a bullet mc off the stage called "bullet". When you press space, the function below called fireBullets() is triggered, but its not working how I want it to, of course. When you shoot a new bullet, there should be another one following behind the first, but instead the bullet already shot disappears and a new one appears in front of the ship. Maybe Im just not using the right strategy, but this is really aggravating me. Any help appreciated!

var i;
function fireBullets() {
if (i >= 2) {
//this should happen AFTER the else statement
_root[newname].duplicateMovieClip(newname);
i++;
} else {
var newname = "bullet"+i;
bullet.duplicateMovieClip(newname);
i++;
}
_root[newname]._x = hero._x;
_root[newname]._y = hero._y-38;
var newname = "bullet"+i;
}
This topic has been closed for replies.

2 replies

Known Participant
January 8, 2009
Hi there,
To get the next highest depth use the code:

var nextDepth = this.getNextHighestDepth();

So then you can do this:

_root[newname].duplicateMovieClip(newname,nextDepth);

Greetings Guido

Creation site internet | Radins | Jeux Concours | Programme TV
kglad
Community Expert
Community Expert
January 8, 2009
duplicateMovieClip() accepts 2 or 3 parameters. you need the 2nd parameter to specify a depth and if that depth is the same as any other object's depth, the other object is removed. so, use a depth parameter that increases with each bullet.