mardi 29 décembre 2015

missing child bullet to spaceship as3

the thing i don't get is i got a symbol called ray that is the bullet for my spaceship and i don't get the bullet on stage when space is triggerd could someone help me with this? and as you can see i write in 1 class so if you know a possible way to let my spaceship shoot a ray in the y.as that would be great.

package {

import flash.display.MovieClip;
import flash.events.*
import flash.ui.Keyboard;

public class SpaceInvaders extends MovieClip {
    var left: Boolean;
    var right: Boolean;
    var shoot: Boolean;
    var upKey: Boolean;
    var downKey: Boolean;
    var player: Player;
    var ray: Ray;

    public function SpaceInvaders() {
        player = new Player();
        ray = new Ray();
        spawn();
        fireSpawn();
        left = false;
        right = false;
        shoot = false;
        upKey = false;
        downKey = false;

        stage.addEventListener(Event.ENTER_FRAME, update);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
    }

    public function spawn() {
        trace("ree");
        player.x = 95;
        player.y = 200;
        this.stage.addChild(player);



    }
    public function fireSpawn(players) {
        trace("fireshoot");

    }


    public function update(e: Event) {
        if (left) {
            player.x -= 10;
            trace("left");
        }
        if (right) {
            player.x += 10;
            trace("right");
        }
        if (shoot) {
            addChild(ray);
            trace("shoot");
        }
        if (upKey) {
            player.y += 10;
            trace("up");
        }
        if (downKey) {
            player.y -= 10;
            trace("down")
        }
    }
    public function keyDownHandler(event: KeyboardEvent): void {
        switch (event.keyCode) {
            case Keyboard.LEFT:
                left = true;
                break;

            case Keyboard.RIGHT:
                right = true;
                break;

            case Keyboard.SPACE:
                shoot = true;
                break;
            case Keyboard.UP:
                upKey = true;
                 break;
            case Keyboard.DOWN:
                downKey = true;
                break;
            default:
                break;
        }
    }

    public function keyUpHandler(event: KeyboardEvent): void {
        switch (event.keyCode) {
            case Keyboard.LEFT:
                left = false;
                break;

            case Keyboard.RIGHT:
                right = false;
                break;

            case Keyboard.SPACE:
                shoot = false;
                break;

            case Keyboard.UP:
                upKey = false;
                break;

            case Keyboard.DOWN:
                downKey = false;
                break;

            default:
                break;
        }
    }
}

}

Aucun commentaire:

Enregistrer un commentaire