HaxeFlixel Logo HaxeFlixel Snippets
  • About
  • Tutorials
  • Back to HaxeFlixel.com
  • Basics
    • Screen
    • Adding
  • Objects
    • Alive
    • Health
  • Sprites
    • Making Sprites
    • Loading Sprites
    • Animation
    • Alpha
    • Color
    • Facing
    • Scale
    • Baked Rotations
  • Text
    • FlxText
    • FlxBitmapText
  • Movement
    • Velocity
    • Acceleration
    • MaxVelocity
    • Gravity
    • Jumping
    • Angle
    • Angular Velocity
    • Angular Acceleration
  • Groups
    • Basic Group
    • Typed Group
    • Recycling
  • Tiling
    • Tileblock
    • Tilemap
  • Overlap
    • Simple Overlap
    • Overlap Callbacks
  • Collision
    • 1-to-1 Collision
    • Immovable
    • Tilemap Collision
    • Moving Platforms
  • Camera
    • Flash
    • Fade
    • Shake
    • Follow
  • Input
    • Basics
    • Keyboard
    • Mouse
    • Button
  • Sound
    • FlxSound

FlxSound

FlxG provides a way of playing sounds, should you not feel like initiating a FlxSound instance.

// Play a sound
FlxG.sound.play();

Demonstration

Source

source/PlayState.hx

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.math.FlxMath;
import flixel.text.FlxText;
import flixel.ui.FlxButton;

class PlayState extends FlxState
{
    override public function create()
    {
        super.create();

        var soundBox:FlxButton = new FlxButton(0, 0, "Play Sound", playSound);
        soundBox.screenCenter();
        add(soundBox);
    }

    function playSound()
    {
        FlxG.sound.play("assets/just-a-breath.mp3");
    }
}
View Source on GitHub

Tags

sound
  1. Home
  2. Sound
  3. FlxSound
Powered By HaxeFlixel Logo HaxeFlixel