Music pauses when I change screens

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Music pauses when I change screens

Postby Charle » Fri Jan 17, 2020 8:45 am

Hello everyone,,
So, I've read the documentation and it states that music is automatically paused on the desktop whenever the dispose() method is called.

This is causing a problem for continuity with my game in that when you change map areas, I first dispose the world (Box2D), spriteBatch, map (Tiled) and mapRenderer, and afterwards reset them to the maps, spriteSheets and world. The thing is, though the map may change, the music may not always change (i.e., if it's the same general area, just a different TiledMap).
mobdro.bio/ luckypatcher.tips/ kodi.bio/
I've tried commenting out the dispose() calls and I've put the audioManager in a separate class. But I still get a pause in the music while the screen is loading and then it resumes right where it left off in the song.

The maps are cut up in a certain way to not reveal the room that comes next, so loading the entire map isn't really an option.

This is not a bug, as the documentation states quite clearly that it is intentional. I was just wondering if anyone else had this problem and if so, if they had a clever workaround. I can't, for the life of me, think of one and scouring Stackoverflow and the Badlogic forums reveals nothing really either--even a google search led to no mention of this issue on any of the blog posts that appeared. I figured maybe there was a way to stop the automatic pause for music when dispose() is called for things not related to music.
Last edited by Charle on Tue Jan 21, 2020 2:51 am, edited 1 time in total.
Charle
 
Posts: 2
Joined: Fri Jan 17, 2020 8:21 am

Re: Music pauses when I change screens

Postby shatterblast » Fri Jan 17, 2020 3:28 pm

If you change a Stage object or its related SpriteBatch, then you're just going to generally have music issues. It's up to you how to handle it.

If you can keep at least one Stage and its related Camera still going, then you can probably handle a transition fine. The Delta variable tends to stop reacting if you totally drop all your Stage objects, which will kill your music altogether.

In other words, it sounds like you want to keep at least one Stage object in the background going for your desired effect. Depending on your Viewport of choice, you typically need to ensure that it's filled with all black or similar instead of just registering nothing, and also, that it fills the entire Viewport or further. Otherwise, your game will end with an Exception in most cases, when you drop all other Stage objects but that last.

You can achieve that black-fill effect with the below code. You typically want it early in your render() method.
Code: Select all
Gdx.gl.glClearColor(0, 0, 0, 0);
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm


Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron