我是一个初学者,我有我的太空入侵者克隆设置,我学会了如何在互联网上制作各种教程的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);
}
}
}
}
我在互联网上研究过,google只显示如何添加音乐,而不是我所说的声音,请帮帮我!我们将一如既往地感谢您的帮助!
发布于 2015-12-23 18:28:31
播放音乐或孤立的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();
}
}
}
}
https://stackoverflow.com/questions/34386143
复制相似问题