I'm a beginner at this, I have my Space Invaders clone set up, I learned how to make flash games on various tutorials on the internet, but with no sound. However, the game runs fine with no errors, but, the sound is not playing when I press the SPACE Key, this is the kind of sound I want. Here is the following code as seen on 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);
}
}
}
}
I have researched on the internet and google shows only how to add music, not the sound I'm talking about, Please Help!!! Any Help would be greatly appreciated as always!!
Playing a music or an isolated SFX is almost the same semantically, but here is a way of easily playing a SFX. It uses an instance of the
FlxSoundclass: