dimanche 18 septembre 2016

how do I make the bullet move Actionsscript 3.0

I am making a very simpel flash game to understand AS3. I have made a cirkel with controls. When I press the space I want to fire a bullet. I have tried for, while loops and different tutorials but I just can't figure out how to do this. This is m code:

import flash.net.drm.LoadVoucherSetting;

//controls 
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
var dir:String = "default";

function reportKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.LEFT)
{
    ball_mc.x -=  10;
    dir = "venstre";
}
if (event.keyCode == Keyboard.RIGHT)
{
    ball_mc.x +=  10;
    dir = "hojre";
}
if (event.keyCode == Keyboard.UP)
{
    ball_mc.y -=  10;
    dir = "op";
}
if (event.keyCode == Keyboard.DOWN)
{
    ball_mc.y +=  10;
    dir = "ned";
}
if (event.keyCode == Keyboard.SPACE)
{
    shootBullet();
}
}

var speed1:int = 1;
function shootBullet():void
{
//instantiate your object
var bullet:Bullets = new Bullets  ;

//add it to the stage
addChild(bullet);

//object will default to x=0 , y=0 so you can define that as well
bullet.x = ball_mc.x;
bullet.y = ball_mc.y +(ball_mc.width/2);

bullet.y += 10 * 2;

}

stop();

Aucun commentaire:

Enregistrer un commentaire