So I’m making a sort of side scrolling arcade type game, and so far I have the backgrounds and everything sorted, the character movement sorted, the sprint function sorted etc…but that’s not important. What *is *important is that I can only make the character fire one projectile at a time.
When the fire button is pressed, the bullet mc loads and starts moving across the screen. The problem starts when you press the fire key again before it’s finished its journey to the other side. Rather than loading a new mc, it appears to just return the original bullet back to the point of origin and start it moving again. Whether it actually creates another mc at all is difficult to tell, as there could be two instances of the clip with different names one on top of the other.
Any help as to why this is occuring and possible solutions would be *greatly *appreciated.
Here is the code I have at the moment (using the method outlined in Kirupa’s ‘How to Fire’ tutorial.)
Code attached to the character:
onClipEvent (enterFrame) {
if (Key.isDown(key.SPACE)){
_root.fire = 1;
_root.i += 1;
duplicateMovieClip(_root.bullet, "bullet" + i, i);
}
}
Code attached to the Bullet Movie Clip:
onClipEvent (load) {
this._visible = 0;
if (_root.fire == 1) {
this._x = _root.bird._x;
this._y = _root.bird._y - 12;
}
}
onClipEvent (enterFrame) {
if (this != _level0.bullet) {
if (_root.fire == 1) {
this._x += 10;
this._visible = 1;
}
if (this._x<0) {
this.removeMovieClip();
}
}
}
Again, any help would be very well recieved :).
Thanks.