【问题标题】:Flixel+ FlashDevelop sound not playingFlixel+ FlashDevelop 声音不播放
【发布时间】:2016-03-26 23:08:57
【问题描述】:

我是这方面的初学者,我已经设置了我的 Space Invaders 克隆,我在互联网上的各种教程上学习了如何制作 Flash 游戏,但没有声音。但是,游戏运行良好,没有错误,但是按空格键时没有声音,这就是我想要的声音。以下是 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);
            }
        }
    }
}

我在互联网上进行了研究,谷歌只显示了如何添加音乐,而不是我正在谈论的声音,请帮助!!!任何帮助将一如既往地不胜感激!

【问题讨论】:

    标签: actionscript-3 flash flashdevelop flixel


    【解决方案1】:

    播放音乐或孤立的 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();
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 2011-02-25
      • 2020-02-15
      • 2015-12-22
      • 2022-01-25
      • 1970-01-01
      相关资源
      最近更新 更多