PDA

View Full Version : shooting problem



mario_hater
January 16th, 2007, 05:37 PM
I've tried 3 ways of doing this and i still keep getting the same result. Is there a way to shoot a bullet from the mouse using the attachMovie? I have got this code, but everytime you click, the previous bullet stops moving.

bullets = new Array();
i = 0;
onMouseDown = function () {
i++;
bullets[i] = attachMovie("bullet", "bullet"+i, i);
bullets[i]._x = _xmouse;
bullets[i]._y = _ymouse;
};
onEnterFrame = function () {
bullets[i]._y -= 10;
};

can anyone point me in the right direction or suggest a tutorial or anything?

SacrificialLamb
January 16th, 2007, 07:32 PM
This is not working because the on onEnterFrame would be on the _root time line and not on ever created instants of the bullets.
this fixes what you have but i would not use this way. I added a for loop in the onEnterFrame so you only have the one onEnterFrame and it’s still on the _root

bullets = new Array();
i = 0;
onMouseDown = function () {
i++;
bullets[i] = attachMovie("bullet", "bullet"+i, i);
bullets[i]._x = _xmouse;
bullets[i]._y = _ymouse;
};
onEnterFrame = function () {
for (j=0; j<=i; j++){
bullets[j]._y -= 10;
}
};
this is how I would do it.
here I add a onEnterFrame to every bullet this allows me to simply add more complicated doe to every bullet i.e. if (this._y > Stage.height){ remove code} or other things like this

i = 0;
onMouseDown = function () {
i++;
temp = attachMovie("bullet", "bullet"+i, i);
temp._x = _xmouse;
temp._y = _ymouse;
temp.onEnterFrame = function () {
this._y -= 10;
}
};

mario_hater
January 17th, 2007, 11:46 AM
thanks :thumb: