I’m trying to get the bullet to go the angle of where the mouse click was. But it doesn’t work! I can’t figure out why, it thinks that the angle is -1 or something I have no idea and copied and pasted code I know and yet it still doesn’t. I’ll post code for non flash 8 users and attach for flash 8 users.
Why isn’t this working, also there’s a problem where it doesn’t delete the movieclips after they’ve left the stage area, dunno why either, doesn’t even show up that they left the bounds when they definately have.
http://www.filefactory.com/?0ae506
Code:
onClipEvent(load)
{
bulletNum = 0;
bullet = new Array();
stageWidth = 500;
stageHeight = 450;
}
onClipEvent(mouseDown)
{
// duplicate the bullet mc
var mc = _root.attachMovie(“bullet”,“bullet”+bulletNum,bulletNum);
mc._x = _root.start._x;
mc._y = _root.start._y;
// set the coords to the mouse clik
var theta:Number = Math.atan2(_ymouse - mc._y, _xmouse - mc._x);
// increment the bullet number
bullet.push({instance:mc, way:theta});
++bulletNum;
// if more than 5 bullets , start again at 0
}
onClipEvent(enterFrame)
{
//deal with existing bullets
for(var i=bullet.length-1;i>=0;i–)
{
//reduce alpha and scale
bullet*.instance._x += Math.cos(bullet*.way) * 10;
bullet*.instance._y += Math.sin(bullet*.way) * 10;
//if this is one off stage, remove it
if(bullet*._x > stageWidth or bullet*._x < 0 or bullet*._y > stageHeight or bullet*._y < 0)
{
//remove array
bullet.splice(0,1);
//remove movie clip
bullet*.instance.removeMovieClip();
trace(‘removed?’);
}
}
}