Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Libgdx game android audio makes game lag  RSS feed

 
Keith Earl
Greenhorn
Posts: 15
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I've been following a tutorial on youtube on how to make a space invaders type of game using Libgdx. The game works fine and I even added audio on my own, however the audio seems to be a problem with running the game on android. On the PC the game works, but with android it runs very very slow and if I remove or comment out all of the audio then the game runs perfectly fine on android. The problem initially was I had no type of assets manager for the audio, but then I created one and still get the same problem. I'll paste all of my coding here and please forgive me if it isn't the correct etiquette. I'm willing to put all of the classes in pastebin as well if I need to. Excluding the typical Desktop and Android launcher classes, there are 14 classes: MyGdxGame, TextureManager, OrthoCamera, VirtualViewport, Assets, , EntityManager, Entity ->( Enemy, Player, Missile), ScreenManager, Screen -> ( GameScreen, GameOverScreen). the ->() indicates that the classes within the () are extending the previous class, GameScreen extending Screen for example.


MyGdxGame


TextureManager


OrthoCamera


VirtualViewport


Assets


EntityManager


Entity


Enemy


Player


Missile


ScreenManager


Screen


GameScreen


GameOverScreen


That's all there is to it sans the launcher classes. Am I going about the assetmanager the wrong way? Again it works perfectly fine on PC, but I would assume that's because it's got better graphics and processing power than my phone hence why it doesn't lag
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I would uncomment the audio line by line until I found a call that looked like it might be causing the lag, and then take it from there.

This may not be your problem but I can tell you that Android audio itself is infamously laggy. You can't get below about 1/10 sec between input and playback, in my experience, in other words no real-time monitoring. Other people reporting other show stoppers. I think I read that 5.x fixes some of it but of course it will still be lousy. Everything about Android is great, except the flat out suckaxx audio.

https://code.google.com/p/android/issues/detail?id=3434
 
Keith Earl
Greenhorn
Posts: 15
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guillermo Ishi wrote:I guess I would uncomment the audio line by line until I found a call that looked like it might be causing the lag, and then take it from there.

This may not be your problem but I can tell you that Android audio itself is infamously laggy. You can't get below about 1/10 sec between input and playback, in my experience, in other words no real-time monitoring. Other people reporting other show stoppers. I think I read that 5.x fixes some of it but of course it will still be lousy. Everything about Android is great, except the flat out suckaxx audio.

https://code.google.com/p/android/issues/detail?id=3434


Yeah I pretty much did that with the audio, as I built the asset manager I would test it and each time it ran slow on android but fine on pc. I guess I'll just have have to look at more audio tutorials for libgdx and see how others did with it. The tutorial I watched on making this game didn't show how to put any sort of sound or audio into it, so I probably have to look further into that to understand it better. I'm sure something's not being disposed properly with the audio and causing the game to lag since that's the only time it does lag when there is audio in the game. Thank you for giving me that link
 
Keith Earl
Greenhorn
Posts: 15
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem maybe (in a way) fixed itself. When I was testing the game out on android, I was doing so through usb debugging. When I would have the cable still attached while the game was running, that's when it goes slow, but unplugging it makes it run fine. So apparently that was the problem all along. I guess some good came out of it though because I did implement another manager into the game which was good practice. By the way, if anyone wants to test out what I have so far, here is the link to the executable jar.

Source

All of the sound effects were created with a small application called Sfxr, the music came from a game called Gradius, and the sprites are from Galaga and Space Invaders.

I still need to add bounding so the ship doesn't go outside of the screen, but other than that I'm pretty proud of it so far and want to make more changes to it, possibly more stages and stage bosses.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice. I've never been able to get usb working on mine, so I wouldn't know. I develop on an emulator then use dropbox or something to get the apk in my phone.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!