Example usage for com.badlogic.gdx.audio Sound setVolume

List of usage examples for com.badlogic.gdx.audio Sound setVolume

Introduction

In this page you can find the example usage for com.badlogic.gdx.audio Sound setVolume.

Prototype

public void setVolume(long soundId, float volume);

Source Link

Document

Changes the volume of the sound instance with the given id as returned by #play() or #play(float) .

Usage

From source file:com.saltosion.gladiator.util.Jukebox.java

License:Open Source License

/**
 * Play sound and set it's volume/*from   w w  w.ja v  a  2  s .  c o m*/
 *
 * @param sound
 * @param volume 0-1f
 * @return long returns sound's id
 */
public long playSound(Sound sound, float volume) {
    long id = playSound(sound);
    sound.setVolume(id, volume);
    return id;
}

From source file:gui.entity.bomb.RemoteBomb.java

@Override
public void explode(Sound sound) {
    //To Execute the sound only once
    if (ExplodeAudioId == -1) {
        ExplodeAudioId = sound.play();//  w  w  w. j a v a  2 s .  com
        sound.setVolume(ExplodeAudioId, AudioManager.getSoundVolume());
    }

    Player player = entityManager.getPlayerManager().getCurrentPlayerObject();
    if (player != null && sound != null) {
        player.playSoundInDistance(sound, ExplodeAudioId, pos, 1);
    }

    //Create new cell and set texture
    TiledMapTileLayer.Cell cellCenter = new TiledMapTileLayer.Cell();
    cellCenter.setTile(new StaticTiledMapTile(explosionCenter));
    cellCenter.getTile().getProperties().put("deadly", null);

    //Explosion center, replaces bomb texture
    map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY(), cellCenter);

    //Explode DOWN
    for (int y = 1; y <= explosionRange; y++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(super.cellPos.getX(), super.cellPos.getY() - y))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
            break;
        }

        if (y != explosionRange) // If not end of explosion
        {
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionYMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cell);
        } else {
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
        }
    }

    //Explode UP
    for (int y = 1; y <= explosionRange; y++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX(), cellPos.getY() + y))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionUpEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cellDown);
            break;
        }

        if (y != explosionRange) // If not end of explosion
        {
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionYMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cell);
        } else {
            //Set end of explosion
            TiledMapTileLayer.Cell cellUp = new TiledMapTileLayer.Cell();
            cellUp.setTile(new StaticTiledMapTile(explosionUpEnd));
            cellUp.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cellUp);
        }
    }

    //Explode RIGHT
    for (int x = 1; x <= explosionRange; x++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() + x, cellPos.getY()))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionRightEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cellDown);
            break;
        }

        if (x != explosionRange) // If not end of explosion
        {
            //Set cell with middle explosion texture
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionXMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cell);

        } else {
            //Set end of explosion
            TiledMapTileLayer.Cell cellRight = new TiledMapTileLayer.Cell();
            cellRight.setTile(new StaticTiledMapTile(explosionRightEnd));
            cellRight.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cellRight);
        }
    }

    //Explode LEFT
    for (int x = 1; x <= explosionRange; x++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionLeftEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellDown);
            break;
        }

        if (x != explosionRange) // If not end of explosion
        {
            //Set cell with middle explosion texture
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionXMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cell);

        } else {
            TiledMapTileLayer.Cell cellLeft = new TiledMapTileLayer.Cell();
            cellLeft.setTile(new StaticTiledMapTile(explosionLeftEnd));
            cellLeft.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellLeft);
        }
    }
}

From source file:gui.entity.bomb.Teleport.java

@Override
protected void explode(Sound sound) {
    for (int mapY = 0; mapY < map.getFloorLayer().getHeight(); mapY++) {
        for (int mapX = 0; mapX < map.getFloorLayer().getWidth(); mapX++) {
            try {
                if (map.getFloorLayer().getCell(mapX, mapY).getTile().getProperties()
                        .containsKey("Spawn-P" + mainP.getPlayerId())) {
                    //Execute sound
                    if (soundId == -1) {
                        soundId = sound.play();
                        sound.setVolume(soundId, AudioManager.getSoundVolume() * 2);
                    }/*from  ww w . j  a  v  a2s.  c om*/

                    mainP.setPosition(new ThinGridCoordinates(mapX, mapY));
                }
            } catch (NullPointerException e) {

            }
        }
    }
    this.isExploded = true;
}

From source file:gui.entity.player.Player.java

public void playSoundInDistance(Sound sound, long id, ThinGridCoordinates soundPos,
        float soundVolumeModificator) {
    float volume = AudioManager.getSoundVolume();

    if (volume != 0) {
        float abstandX = Math.abs(Math.abs(soundPos.getX()) - Math.abs(pos.getX()));
        float abstandY = Math.abs(Math.abs(soundPos.getY()) - Math.abs(pos.getY()));

        // Ist der Abstand zur X Achse groesser
        if (abstandX > abstandY) {
            volume = volume - (abstandX / 2500);
        } else {//  ww w  . j a  v a 2  s.  c  o  m
            volume = volume - (abstandY / 2500);
        }

        if (volume < 0) {
            volume = 0.01f;
        }
    }
    sound.setVolume(id, volume * soundVolumeModificator);
}

From source file:gui.screen.StartScreen.java

@Override
public void render(float f) {
    //Clear Screen
    Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);

    //Draw stage// w  w  w .  j a v a 2s.  c  om
    stage.act(Constants.DELTATIME);
    stage.draw();

    if (flashingTimer >= endFlashingTimer) {
        if (pressAnyKey.isVisible()) {
            pressAnyKey.setVisible(false);
        } else {
            pressAnyKey.setVisible(true);
        }
        flashingTimer = 0;
    } else {
        flashingTimer += Constants.DELTATIME;
    }

    if (inputHandler.isAnyKey() || hideTimer != 0) {
        pressAnyKey.setVisible(false);

        AudioManager.getCurrentMusic().dispose();

        if (hideTimer == 0) {
            //Add click sound
            Sound sound = AudioManager.getNormalExplosion();
            long id = sound.play();
            sound.setVolume(id, AudioManager.getSoundVolume() * Constants.NORMALBOMBEXPLOSIONMOD);
        }

        if (hideTimer >= endHideTimer) {
            game.setScreen(new MenuScreen(game, client, server));
        } else {
            hideTimer += Constants.DELTATIME;
        }
    }

    /*------------------SWITCH TO FULLSCREEN AND BACK------------------*/
    super.changeToFullScreenOnF12();

}