簡體   English   中英

Flixel + FlashDevelop聲音無法播放

[英]Flixel+ FlashDevelop sound not playing

我是一個初學者,我已經設置了Space Invaders克隆游戲,並且在互聯網上的各種教程中學習了如何制作Flash游戲,但是沒有聲音。 但是,游戲運行正常,沒有錯誤,但是,當我按SPACE鍵時,聲音沒有播放,這是我想要的聲音。 這是在PlayerShip.as上看到的以下代碼:

package
{
    import org.flixel.*;

    public class PlayerShip extends FlxSprite       
    {
        [Embed(source = "../img/ship.png")] private var ImgShip:Class;  
        [Embed(source = "../snd/shoot.mp3")] private var ShootEffect:Class;


        public function PlayerShip()
        {

            super(FlxG.width/2-6, FlxG.height-12, ImgShip);
        }


        override public function update():void
        {

            velocity.x = 0;             

            if(FlxG.keys.LEFT)
                velocity.x -= 150;      
            if(FlxG.keys.RIGHT) 
                velocity.x += 150;      


            super.update();


            if(x > FlxG.width-width-4)
                x = FlxG.width-width-4; 
            if(x < 4)
                x = 4;                  



            if (FlxG.keys.justPressed("SPACE"))

            {

                var bullet:FlxSprite = (FlxG.state as PlayState).playerBullets.recycle() as FlxSprite;
                bullet.reset(x + width/2 - bullet.width/2, y);
                bullet.velocity.y = -140;
                FlxG.play(ShootEffect);
            }
        }
    }
}

我已經在互聯網上進行了研究,谷歌只顯示了如何添加音樂,而不是我正在談論的聲音,請幫助!!! 一如既往,任何幫助將不勝感激!

播放音樂或孤立的SFX在語義上幾乎相同,但這是一種輕松播放SFX的方法。 它使用FlxSound類的實例:

package
{
    import org.flixel.*;

    public class PlayerShip extends FlxSprite       
    { 
        [Embed(source = "../snd/shoot.mp3")] private var ShootEffect:Class;


        private var shootSound:FlxSound;


        public function PlayerShip()
        {

            super(FlxG.width/2-6, FlxG.height-12, ImgShip);

            // Instantiate and load the SFX
            shootSound = new FlxSound();
            shootSound.loadEmbedded(ShootEffect);
        }


        override public function update():void
        {

            if (FlxG.keys.justPressed("SPACE"))

            {
                // Play the SFX
                shootSound.play();
            }
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM