本文整理匯總了Java中com.badlogic.gdx.audio.Music類的典型用法代碼示例。如果您正苦於以下問題:Java Music類的具體用法?Java Music怎麽用?Java Music使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Music類屬於com.badlogic.gdx.audio包,在下文中一共展示了Music類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: playSongNoStop
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
/**
* Plays a song without stopping any currently playing songs. This should only be used
* when we know the current song is about to end, for seamless transitions between
* introductions and looping portions of songs.
* @param fileName
* @param looping
*/
protected void playSongNoStop(final String fileName, final boolean looping) {
loadSong(fileName);
Music music = songs.get(fileName);
currentSong = music;
currentSongFileName = fileName;
currentSong.setLooping(looping);
currentSong.play();
}
示例2: Sounds
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
/**
* Sounds constructor.
* Plays the background music and initializes the game dependent sounds.
*
* @param assetManager Place where the sounds and musics are gotten from.
*/
public Sounds(AssetManager assetManager) {
this.assetManager = assetManager;
loadSounds();
Music music = assetManager.get("music/Artofescapism_-_Three_Star_Sky.mp3");
music.setVolume(0.5f);
music.setLooping(true);
music.play();
//Initializing the game different sounds
powerup = assetManager.get("music/item.mp3");
jump = assetManager.get("music/jump.wav");
lost = assetManager.get("music/lost.wav");
won = assetManager.get("music/won.wav");
water = assetManager.get("music/water.wav");
}
示例3: onInit
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
@Override
protected void onInit(ScreenBasedGame game, AssetManager assetManager) {
// load assets
assetManager.load(MUSIC_PATH, Music.class);
assetManager.load(BACKGROUND_IMAGE_PATH, Texture.class);
assetManager.finishLoadingAsset(MUSIC_PATH);
assetManager.finishLoadingAsset(BACKGROUND_IMAGE_PATH);
// get assets
this.music = assetManager.get(MUSIC_PATH, Music.class);
this.bgTexture = assetManager.get(BACKGROUND_IMAGE_PATH, Texture.class);
// generate fonts
this.titleFont = BitmapFontFactory.createFont("./data/font/spartakus/SparTakus.ttf", 48, Color.WHITE,
Color.BLUE, 3);
// this.font2 =
// BitmapFontFactory.createFont("./data/font/spartakus/SparTakus.ttf",
// 48, Color.RED, Color.WHITE, 3);
this.font1 = BitmapFontFactory.createFont("./data/font/arial/arial.ttf", 18, Color.WHITE);
this.font2 = BitmapFontFactory.createFont("./data/font/arial/arial-bold.ttf", 24, Color.WHITE, Color.RED, 3);
// generate credits text array
try {
this.generateCreditLines();
} catch (IOException e) {
e.printStackTrace();
// TODO: remove this line and handle exception with exception window
System.exit(0);
}
Gdx.input.setInputProcessor(null);
}
示例4: loadAssets
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
private void loadAssets() {
InternalFileHandleResolver fileHandler = new InternalFileHandleResolver();
assetManager = new AssetManager(fileHandler);
assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(fileHandler));
assetManager.load(SKIN_PATH, Skin.class);
assetManager.load(MASTER_PATH, TextureAtlas.class);
assetManager.load(FONT_NORMAL_PATH, FreeTypeFontGenerator.class);
assetManager.load(FONT_BOLD_PATH, FreeTypeFontGenerator.class);
assetManager.load(MUSIC_PATH, Music.class);
assetManager.load(MAIN_MENU_MUSIC_PATH, Music.class);
assetManager.load(GOOD_PATH, Sound.class);
assetManager.load(HALF_PATH, Sound.class);
assetManager.load(BAD_PATH, Sound.class);
assetManager.finishLoading();
}
示例5: initMusic
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public void initMusic() {
Music music;
switch (level) {
case 0: //第一關
//初始化音樂
music = MyGdxGame.assetManager.getMusic(Constant.LEVEL_0_BGM);
music.setLooping(true);
music.play();
break;
case 1: //第二關
case 2: //第三關
case 3: //第四關
music = MyGdxGame.assetManager.getMusic(Constant.LEVEL_1_BGM);
music.setLooping(true);
music.play();
break;
case 4: //第五關背景音樂
music = MyGdxGame.assetManager.getMusic(Constant.LEVEL_2_BGM);
music.setLooping(true);
music.play();
break;
}
}
示例6: CutsceneStoneAge
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public CutsceneStoneAge(MyGdxGame myGdxGame) {
this.myGdxGame = myGdxGame;
batch = myGdxGame.batch;
sr = myGdxGame.sr;
viewport = myGdxGame.viewport;
camera = myGdxGame.camera;
font = myGdxGame.font;
particles = new Particles();
bg = new Sprite(new Texture("sprites/orange.png"));
girl = new Sprite(new Texture("sprites/girl.png"));
stone = new Sprite(new Texture("sprites/stein_angemalt.png"));
hominideSitzend = new Sprite(new Texture("sprites/hominide_sitzend.png"));
hominideDuckend = new Sprite(new Texture("sprites/hominide_duckend.png"));
hominideStehend = new Sprite(new Texture("sprites/hominide_stehend.png"));
assetManager = new AssetManager();
assetManager.load("music/tusch.mp3", Sound.class);
assetManager.load("music/5_steinzeit.mp3", Music.class);
assetManager.finishLoading();
tusch = assetManager.get("music/tusch.mp3", Sound.class);
musicStoneAge = assetManager.get("music/5_steinzeit.mp3", Music.class);
}
示例7: LogoScreen
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public LogoScreen(SpriteBatch batch, ShapeRenderer shapeRenderer, FitViewport viewport, OrthographicCamera camera) {
this.batch = batch;
this.shapeRenderer = shapeRenderer;
this.viewport = viewport;
this.camera = camera;
spriteThere = new Sprite(new Texture("there.png"));
spriteFactory = new Sprite(new Texture("factory.png"));
spriteLibGdxLogo = new Sprite(new Texture("libgdx.png"));
AssetManager am = JewelThief.getInstance().getAssetManager();
am.load("audio/sounds/keyboard.ogg", Sound.class);
am.load("audio/sounds/keyboard_go_back.ogg", Sound.class);
am.load("audio/sounds/re.ogg", Sound.class);
am.load("audio/sounds/libgdx.ogg", Music.class);
am.finishLoading();
soundTypeTheRefactory = am.get("audio/sounds/keyboard.ogg", Sound.class);
soundGoBackOnKeyboard = am.get("audio/sounds/keyboard_go_back.ogg", Sound.class);
soundTypeRe = am.get("audio/sounds/re.ogg", Sound.class);
musicLibGdxJingle = am.get("audio/sounds/libgdx.ogg", Music.class);
resetAnimation();
}
示例8: init
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public static void init() {
assetManager.setLoader(TiledMap.class, new TmxMapLoader());
for (Assets.Fonts font : Assets.Fonts.values()) {
assetManager.load(font.getPath(), BitmapFont.class);
}
for (Assets.Textures texture : Assets.Textures.values()) {
assetManager.load(texture.getPath(), Texture.class);
}
for (Assets.Maps map : Assets.Maps.values()) {
assetManager.load(map.getPath(), TiledMap.class);
}
for (Assets.Musics music : Assets.Musics.values()) {
assetManager.load(music.getPath(), Music.class);
}
for (Assets.Sounds sound : Assets.Sounds.values()) {
assetManager.load(sound.getPath(), Sound.class);
}
assetManager.finishLoading();
}
示例9: playIntroTheme
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public void playIntroTheme()
{
if(currentMusic!=null)
currentMusic.stop();
currentMusic = intro_loop_intro;
intro_loop_intro.setOnCompletionListener(new Music.OnCompletionListener() {
@Override
public void onCompletion(Music music) {
currentMusic = intro_loop_main;
currentMusic.setVolume(vol);
currentMusic.play();
currentMusic.setVolume(vol);
}
});
currentMusic.setVolume(vol);
currentMusic.play();
currentMusic.setVolume(vol);
nextMusic = currentMusic;
}
示例10: playNext
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public void playNext(){
System.out.println("next sound");
Music old = currentMusic;
if(nextMusic == null){
nextMusic = currentMusic;
}
if(nextMusic == currentMusic)
return;
currentMusic=nextMusic;
currentMusic.setVolume(vol);
currentMusic.play();
currentMusic.setVolume(vol);
old.stop();
old = null;
}
示例11: run
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public void run() {
if (challengeAudio != null && challengeAudio.isPlaying()) {
challengeAudio.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(Music music) {
music.setOnCompletionListener(null);
stage.addAction(actionLoadNextChallengeQuick());
}
});
return;
}
// 5-minute check
if (totalElapsed > maxTime_secs) {
log("=== SESSION TIME UP!");
pausedStage.addAction(actionShowCompletedDialog());
userPause();
return;
}
loadNextChallenge();
}
示例12: loadNewChallengeAudio
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
private void loadNewChallengeAudio(final String newActiveAudioFile) {
Gdx.app.postRunnable(new Runnable() {
public void run() {
if (challengeAudio != null) {
challengeAudio.stop();
}
if (activeAudioFile != null) {
if (assets.isLoaded(activeAudioFile)) {
assets.unload(activeAudioFile);
}
}
assets.load(newActiveAudioFile, Music.class);
assets.finishLoadingAsset(newActiveAudioFile);
challengeAudio = assets.get(newActiveAudioFile, Music.class);
challengeAudio.play();
activeAudioFile = newActiveAudioFile;
}
});
}
示例13: playMusicBeautifully
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public void playMusicBeautifully(String name, Stage stage) {
final Music music = musics.get(name);
if (music == null) {
Logger.error("there is no music for " + name);
return;
}
music.setVolume(0);
if (!usesMusic) {
disabledMusics.add(music);
} else {
music.play();
}
music.setLooping(true);
playingMusics.add(music);
Action action = new TemporalAction(5f, Interpolation.linear) {
@Override protected void update(float percent) {
music.setVolume(percent * volume);
}
};
stage.addAction(action);
replaceAction(music, action);
}
示例14: stopMusicBeautifully
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
public void stopMusicBeautifully(String name, Stage stage) {
final Music music = musics.get(name);
if (music == null) {
Logger.error("there is no music for " + name);
return;
}
final float initialVolume = music.getVolume();
Action action = new TemporalAction(2f, Interpolation.linear) {
@Override protected void update(float percent) {
music.setVolume(initialVolume - percent * initialVolume);
}
@Override protected void end() {
music.stop();
playingMusics.remove(music);
disabledMusics.remove(music);
}
};
stage.addAction(action);
replaceAction(music, action);
}
示例15: render
import com.badlogic.gdx.audio.Music; //導入依賴的package包/類
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (APP.assets.update() && !assetsLoaded)
{
bg = APP.assets.get("backgrounds/map.png", Texture.class);
bg.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
APP.loadingScreen2 = new LoadingScreen2(APP, font, bg);
menuScreenAtlas = APP.assets.get("atlases/menuscreen.pack", TextureAtlas.class);
APP.menuScreen = new MenuScreen(APP, font, bg, new MenuHud(APP, APP.viewport, APP.batch, menuScreenAtlas.findRegion("giftiz_logo"), menuScreenAtlas.findRegion("giftiz_logo_badge"), menuScreenAtlas.findRegion("giftiz_logo_warning"), menuScreenAtlas.findRegion("title"), menuScreenAtlas.findRegion("play-button-up"), menuScreenAtlas.findRegion("play-button-down"), menuScreenAtlas.findRegion("highscore-button-up"), menuScreenAtlas.findRegion("highscore-button-down")), APP.assets.get("music/epictheme.ogg", Music.class));
assetsLoaded = true;
startTime = System.currentTimeMillis();
}
if (assetsLoaded && System.currentTimeMillis() - startTime >= 5000)
APP.setScreen(APP.menuScreen);
APP.batch.setProjectionMatrix(APP.camera.combined);
APP.batch.begin();
font.render(APP.batch, "Loading", Constants.V_WIDTH / 2, Constants.V_HEIGHT / 2, true);
APP.batch.end();
}