I'm currently working on an android project in which I'm making a game using libgdx. I've created a splash screen which shows up in the beginning for a second, but it doesn't do any file loading currently. The problem I'm having is that when I'm loading the files like the music and sound files, they are all loaded once I hit play. Because there are a decent number of sound files it's takes a while to load the game after someone hits play. My question is there anyway to move the loading of these files to the splash screen? For those familiar with libgdx and android studio, currently my splash screen code is in a separate module under "android" and the rest of the program is under "core" (separate module core). When I try initializing the sound files in the core module I can't access them in the core module which makes sense considering they are different modules all together and I can't move the android module which does the splash screen and such into core because then I would lose the android studio setup that is made. If I can't load the files earlier in the program is there any way to load them faster upon game start? I'm sorry if my question isn't clear enough.. I'm trying to be as clear as I can be.
Also when I try to use say a thread and then load files with libgdx using say:
atk1 = (Gdx.audio.newSound(Gdx.files.internal("sounds/fight/attack1.wav")));
Here the sounds are in the assets folder. I keep getting an error when I try doing it in the android module but no issues when doing it in core. Why can't I load them in the android manager like this?
You can add a loading screen in between, after splash and before actual game. Use a AssetManager to load all of them and keep there reference alive.
But i would recommend moving splash screen to core and load when the splash screen is displayed in background. You can still access android methods from core if you want to by creating an interface and it looks better that way.
Related
i have a problem launching my game on my phone or any virtual device, I've exported the game from Buildbox to an android source code and imported into eclipse without any problem and export it to android application also with no problem, when I tried to test the game on my device crushed "Unfortunately App name has stopped", I've run it on my virtual device and those are the logs that gave me.
Usually when a game crashes when testing the app on a mobile device you need to optimize your atlas.
Usually you are having problems with the images and animations that are too big and too heavy they make the game crash.
In order to optimize the atlas go to View > Atlases
You atlases should look like this one. So many images should exist in 1 atlas. You need to check all your atlases and if you have only 4 or 5 images per atlas you need to redo the sizes for those specific animations and reface them in the atlas.
After you do all that design work and replace them in Buildbox (you need to erase all the old images that you had) and then you go to the atlases and optimize and rebuild the atlases.
Allways keep a backup before doing all of this.
Then export and build another application and you should be good to go.
Option 2:
If it's still not working, check you scenes as they may be too long and may be using too much memory at once and that should be making the game crash.
I have made a light weight java web-server serving html files and static content (made with pure java library nanohttpd), i have successfully made a javaFX launcher window that has a single button, clicking button simply runs the server in the background and opens the localhost URL in Android/PC browser (I was unsuccessful in making an IOS version using javaFX)
I am thinking of using libGDX as "launcher window" because of IOS support and access to mobile specific hardware like SMS/GPS which javaFX don't have.
I am targeting IOS/Android/PC, I'd like to ask libGDX developers how possible is this given my target platforms?
Yes you can
There's a catch though, you may have to build the UI the game dev way
I've made a game or two using it and had rather steep learning curve in the beginning to get a hold on to how it worked. For example you'll have to provide the images for button, background and also, the pressed view of the button... like that. But your app is not a game. So you won't have to worry that much.
Once you learned how to place them in the screen successfully, there is not much to worry about because the API provides everything you need to carry on from there.
Also I found enough resources/tutorials online enough to make a game from ground up. So you'll definitely can.
And there's very little to worry about your multi-platform problem.
I have a simple kids app which teaches things such as colors, numbers, etc... which I am currently developing. It uses what I would consider "standard android java programming (Single Xml/java class)." I also have a simple game with a Dinosaur that jumps over letters using libgdx.
My question is, I would like to have the game as part of the "overall" app. I would like to know if it is even possible to add a libgdx game to an android native application. I tried adding the appropriate files to my app, but this caused a compile error, could someone point me to a place where I could find help on this issue, or perhaps let me know if what I am wanting to do is even possible? Thanks.
---To clairify, my main app has a menu which takes you to activities. I would like the libgdx game to be one of the activities.
---Edit to response---I compile using Gradle and have more errors than I can count. I've since removed the libgdx game from the app so I am not sure of specific errors, but iirc there were over 100, many of which were R issues, which I could have figured out, but I couldn't find anything on either S.O. or the web saying it was even possible to add libgdx to a non-libgdx app.
You can integrate your App with your libgdx game.
AndroidLauncher.java is your libgdx Activity and you can move from one activity to another using Intent.
intent = new Intent(this, AndroidLauncher.class);
startActivity(intent);
and movement from libgdx AndroidLauncher.java, you need to call it from inside the core project classes. You need to use an interface.
https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code
If your game is sub view of your App.The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration) that will return a View you can add to your layout.
Pros.-Code is already you have,only you need to integrate.
Cons.-you need to maintain OpenGL Context Loss. Libgdx do for you.
In Libgdx your entire game is just a single Activity. You can start it as any other activity from your code.
Please follow Can I run an Activity before running libgdx? for details.
I'm working on an android app in which the user can play multiple Unity games. However, achieving this simple aspect has proven to be too complicated with Unity, if even possible.
After analyzing how Unity on Android works, I understood that it uses a bunch of libraries (called libmain.so, libunity.so and libmono.so), these three libraries refer to the code of the actual game which is stored inside the apk of the android app, specifically in "assets/bin/Data/" directory. The directory is hard-coded inside the code of the libraries, and everything in the libraries is legally prevented from being changed.
So, in order to allow the users to play multiple games, I thought that I could place the game that the user currently wants to play inside the "assets/bin/Data" directory, and so when the Unity libraries want to start the game, they will find it in "assets/bin/Data" and will start it. And then when the user wants to play another game, I simply replace the files of the old game in "asseets/bin/Data" with the files of the new game, and the Unity libraries will thus play the other game, and so on.
However, this wouldn't work, because an android app is not allowed to modify its own apk.
So, to solve this problem, I thought that I could put the files of the game to be played somewhere in the external or internal storage of the app, and then add a symbolic link (shortcut) to those files inside "assets/bin/Data".
That way, when the libraries of Unity want to play the game, they will go to the "assets/bin/Data" directory, where they will find shortcuts to the actual game in the app's storage, and since I can freely change the content of the app's storage, then I will be able to replace the game on demand.
My question is: Is it possible to create a symbolic link (shortcut) from the app's assets to the app's storage?? If yes, how??
If anything is unclear please ask me to elaborate
Thank you
No, it's not possible to do this. The assets included in the APK are not expanded to be on the device filesystem. They are accessed in-place via the AssetManager APIs.
It would be an enormous security hole to allow an app to replace itself without the user knowing or bypassing the package installation path provided by the framework. If all you need to do is push down asset type updates (graphics, levels, sounds, etc.) then consider using an OBB or other downloadable asset to extend the app.
According to the LibGDX web page:
Android applications can have multiple activities. Libgdx games should usually only consist of a single activity. Different screens of the game are implemented within libgdx, not as separate activities. The reason for this is that creating a new Activity also implies creating a new OpenGL context, which is time consuming and also means that all graphical resources have to be reloaded.
However, this isn't impossible to do - just undesirable.
I'm building an app that is designed to hold a few games built in LibGDX, as well as some information alongside it - video/audio, text with illustrations, and so on, describing the development of the games.
Is it a better idea to build this as a native android application that launches and tears down LibGDX whenever the user wants to play a game? Or should I write the entire app through LibGDX and do try and do the non-game stuff using UI libraries and so on?
I'm sorry I can't nail this down to a more specific question. I'm really interested to know before I embark down the wrong road.
The consensus in a linked Reddit thread here is that setting up and tearing down a LibGDX activity isn't such a huge overhead, particularly if the games are small (which they are in my case).
I'm going to opt for this solution, and simply shut down the activity whenever the user stops playing a game.