1

新しいクラス(Fireball.as)を作成し、クラス名の後に「extends FlxSprite」と入力して、火の玉用のカスタムFlxSpriteを作成しました。コンストラクターでは、「shoot()」と呼ばれる関数を呼び出します。この関数は、ターゲットに向けてサウンドを再生します。

private function shoot():void {
    dx = target.x - x;
    dy = target.y - y;
    var norm:int = Math.sqrt(dx * dx + dy * dy);
    if (norm != 0) {
        dx *= (10 / norm);
        dy *= (10 / norm);
    }
    FlxG.play(soundShoot);
}


次に、すべての火の玉をゲーム状態(PlayState.as)に保持する配列を作成しました。

public var fire:Array = new Array();


次に、私のinput()関数で、誰かがマウスボタンを押すと、配列内の新しいFireballが押されます。

if (FlxG.mouse.justPressed()) {
    fire.push(new Fireball(x, y, FlxG.mouse.x, FlxG.mouse.y));
}


しかし、私がそれをテストすると、それは音を鳴らすだけで、火の玉は現れません。火の玉は舞台裏のどこかにあると思いますが、どうすれば直せますか?

それが役立つ場合は、Fireball.asのコンストラクターを次に示します。

public function Fireball(x:Number, y:Number, tar_x:Number, tar_y:Number) {
    dx = 0;
    dy = 0;
    target = new FlxPoint(tar_x, tar_y);
    super(x, y, artFireball);
    shoot();
}
4

2 に答える 2

1

それらをステージに追加する必要があると思います。

if (FlxG.mouse.justPressed()) {
    var fireball:Fireball = new Fireball(x, y, FlxG.mouse.x, FlxG.mouse.y);
    fire.push(fireball);

    // This line needs to be changed if you add the fireball to a group, 
    //  or if you add it to the stage from somewhere else
    add(fireball);
}

うまくいったかどうか教えてください。

于 2013-02-18T00:39:18.037 に答える