Skip to content
Anastasia Laczko edited this page Jun 11, 2021 · 2 revisions

Introduction

Audio, e.g. Sounds and music files, can be easily added into the game using libgdx Sound and Music. There is no single audio service, instead audio can be played when and where needed once loaded by the ResourceService.

Usage

Example: Sound Effect

  1. Load sound: Ensure the sound file has been loaded in an active resource batch by the Resource Service using loadSounds().
private static final String[] soundsToLoad = {"sounds/sound.ogg"};
resourceService.loadSounds(soundsToLoad);
  1. Play sound: Retrieve the sound from the Resource Service using getAsset(). Configure the playback settings, then use play() to play the file.
Sound sound = ServiceLocator.getResourceService().getAsset("sounds/sound.ogg", Sound.class);
sound.play();

Example: Background Music

  1. Load music: Ensure the music file has been loaded in an active resource batch by the Resource Service using loadMusic().
private static final String[] musicToLoad = {"sounds/music.mp3"};
resourceService.loadMusic(musicToLoad );
  1. Play music: Retrieve the music from the Resource Service using getAsset(). Configure the playback settings, then use play() to play the music. The following example is set to loop, and to play with volume at 30%.
Music music = ServiceLocator.getResourceService().getAsset("sounds/music.mp3", Music.class);
music.setLooping(true);
music.setVolume(0.3f);
music.play();

Table of Contents

Home

How to Play

Introduction

Game Features

Main Character

Enemies
The Final Boss

Landscape Objects

Shop
Inventory
Achievements
Camera

Crystal

Infrastructure

Audio

User Interfaces Across All Pages
Juicy UI
User Interfaces Buildings
Guidebook
[Resource Management](Resource-Management)
Map
Day and Night Cycle
Unified Grid System (UGS)
Polishing

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally