hnicky
09-22-2011, 06:00 PM
I am developing a game in AS 3.0. The issue i have is it keeps shooting from the last position and angle instead of updating it when i move the hero with arrow keys. Can someone please help me with updating its shooting (both x, y and angle) after i move it with arrow keys. Perhaps direct me to an example online? or show me code example. Thank you.
SWF File - Sky Raid game - wwwdotfreewebsdotcom/hundalraj/gamesdothtml
Arrow Keys to move and Mouse Click to shoot.
[as3]
if (fireBulletFlag && delay_completed)
{
var ang = outer_mc.rotation;
delay_completed = false;
delay.addEventListener(TimerEvent.TIMER, on_delay_over);
delay.start();
for (var i:uint = 0; i < bullets_per_time; i++) // bullets fired by hero
{
var dist_x:Number = outer_mc.x + game_container.x - mouseX;
var dist_y:Number = outer_mc.y + game_container.y - mouseY;
bullet = new Bullet_mc(enemy, outer_mc.x, outer_mc.y, Math.atan2(dist_y, dist_x));
game_container.addChild(bullet); // add bullet here
}
[as3]
Here outter_mc is the hero MovieClip.
SWF File - Sky Raid game - wwwdotfreewebsdotcom/hundalraj/gamesdothtml
Arrow Keys to move and Mouse Click to shoot.
[as3]
if (fireBulletFlag && delay_completed)
{
var ang = outer_mc.rotation;
delay_completed = false;
delay.addEventListener(TimerEvent.TIMER, on_delay_over);
delay.start();
for (var i:uint = 0; i < bullets_per_time; i++) // bullets fired by hero
{
var dist_x:Number = outer_mc.x + game_container.x - mouseX;
var dist_y:Number = outer_mc.y + game_container.y - mouseY;
bullet = new Bullet_mc(enemy, outer_mc.x, outer_mc.y, Math.atan2(dist_y, dist_x));
game_container.addChild(bullet); // add bullet here
}
[as3]
Here outter_mc is the hero MovieClip.