Package com.teamjmonkey.appstates

Source Code of com.teamjmonkey.appstates.BackgroundMusicAppState

package com.teamjmonkey.appstates;

import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.audio.AudioNode;
import com.jme3.audio.AudioNode.Status;
import com.teamjmonkey.GameNameGoesHere;

public class BackgroundMusicAppState extends AbstractAppState {

    private boolean isActive;
    private AudioNode music;

    public BackgroundMusicAppState(GameNameGoesHere myApp) {
        music = new AudioNode(myApp.getAssetManager(), "Sounds/Music/bg1.ogg", true);
        music.setLooping(false);
        music.setVolume(0.25f);
        music.setPositional(false);
        music.setDirectional(false);
    }

    @Override
    public void stateAttached(AppStateManager stateManager) {
        isActive = true;
    }

    @Override
    public void stateDetached(AppStateManager stateManager) {
        isActive = false;
        music.stop();
    }

    @Override
    public void update(float tpf) {
        if (isActive) {
            if (music.getStatus() == Status.Stopped) {
                music.play();
            }
        }
    }
}
TOP

Related Classes of com.teamjmonkey.appstates.BackgroundMusicAppState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.