-
Notifications
You must be signed in to change notification settings - Fork 0
Sound effects
Sound effects are small audio samples, usually no longer than a few seconds, that are played back on specific game events such as a character jumping or shooting a gun.
Sound effects can be stored in various formats. Libgdx supports MP3, OGG and WAV files. RoboVM (iOS) currently does not support OGG files.
note: On Android, a Sound instance can not be over 1mb in size. If you have a bigger file, use Music
Sound effects are represented by the Sound interface. Loading a sound effect works as follows:
Sound sound = Gdx.audio.newSound(Gdx.files.internal("data/mysound.mp3"));This loads an audio file called "mysound.mp3" from the internal directory data.
Once we have the sound loaded we can play it back:
sound.play(1.0f);This will playback the sound effect once, at full volume. The play method on a single Sound instance can be called many times in a row, e.g. for a sequence of shots in a game, and will be overlaid accordingly.
More fine-grained control is available. Every call to Sound.play() returns a long which identifies that sound instance. Using this handle we can modify that specific playback instance:
long id = sound.play(1.0f); // play new sound and keep handle for further manipulation
sound.stop(id); // stops the sound instance immediately
sound.setPitch(id, 2); // increases the pitch to 2x the original pitch
id = sound.play(1.0f); // plays the sound a second time, this is treated as a different instance
sound.setPan(id, -1, 1); // sets the pan of the sound to the left side at full volume
sound.setLooping(id, true); // keeps the sound looping
sound.stop(id); // stops the looping sound Note that these modifier methods will not work in the JavaScript/WebGL back-end for now.
Once you no longer need a Sound, make sure you dispose of it:
sound.dispose();Accessing the sound after you disposed of it will result in undefined errors.
-
开发者指南
- Introduction
- 设置开发环境 (Eclipse, Intellij IDEA, NetBeans)
- 创建、运行、调试、打包你的项目
- 源码
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- Profiling
- Viewports
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprites * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * NinePatches * Bitmap Fonts * Distance field fonts * Color Markup Language * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * Texture Compression * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Table * Skin
- 3D Graphics * Quick Start * Models * Material and environment * ModelBatch * ModelBuilder, MeshBuilder and MeshPartBuilder * 3D animations and skinning * Importing Blender models in LibGDX * 3D Particle Effects * Perspective Camera ?? * Picking ?? * Decals
- Managing Your Assets
- Internationalization and Localization
- 实用程序
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- 工具
- 扩展
- Artificial Intelligence
- gdx-freetype
-
Physics
* Box2D
* Bullet Physics * [Setup](../Bullet Wrapper - Setup) * [Using the wrapper](../Bullet Wrapper - Using the wrapper) * [Using models](../Bullet Wrapper - Using models) * [Contact callbacks](../Bullet Wrapper - Contact callbacks) * [Custom classes](../Bullet Wrapper - Custom classes) * [Debugging](../Bullet Wrapper - Debugging)
- Using libgdx with other JVM languages
- Third Party Services
- 文章