B4A Library libGDX - Game Engine



One of the best game engines for Android is now available to B4A users. Unleash your creativity!

You can read a description of this library in this guide.

Download for B4A v10.60 and older (4 MB)
Download for B4A v10.70 and newer (4 MB)

Starting from version 1.13, the library is compiled with Java 8, and thus requires a recent version of B4A and Java 8+.
To install the library, copy the .jar file and the .xml file in your libraries folder.

This library is not compatible with the Debug mode. Ensure that you always compile in Release mode.

Download also the examples and templates.

You can reduce the weight of the library if you want to keep your APK file as small as possible. Read this post to learn how to create your Lite version.

Tutorials:
How to make games
Introduction to the libGDX library
PacDroid: from scratch to fun
Shaders

Take also a look at the Cloney Bird tutorial by andymc.

Plugins:
Box2DLights
SpecialFX

Versions:
 
Last edited by a moderator:

sterlingy

Active Member
Licensed User
Longtime User
Did you remove Activity.Finish at the end of the demo? Because you cannot play any sound if the activity is finished.
I did not include Activity.Finish.
 

sterlingy

Active Member
Licensed User
Longtime User
I just tried to play the demo sound and it worked fine. Is your sound file smaller than 1 MB (once uncompressed)?
The file is 65k, and I tried a different file just to make sure. Also, If I load the file without using Asset Manager, it works just fine.
 

sterlingy

Active Member
Licensed User
Longtime User

Attachments

  • Swarm-No Audio.zip
    35.1 KB · Views: 223

sterlingy

Active Member
Licensed User
Longtime User
I have to admit that's a complete mystery to me. I'm unable to explain why there's no sound played.
I have to admit, that while we don't have a solution, as of yet, at least I've stumped the genius, makes me feel like less of an idiot, though I am one and you are not.

This isn't a critical issue for me. I wanted the horse sound to trigger after all the assets are loaded. If I do it the old school way, which you can see towards the end of LG_Create, you will see several other sounds being loaded. For some reason, LGS1_Show would never play the horseSFX, but LGS2_Show would. I always assumed this was because it hadn't finished loading.

Oddly, even when I put the "horseSFX.Initialize("audio/horse_neigh.mp3")" at the top of the list of sounds being loaded, it still wouldn't play.

-S
 

Informatix

Expert
Licensed User
Longtime User
It seems there's a delay between the moment where you load the file and the moment where you can play it. It's not related at all to libGDX but to the SoundPool class of the Android API. You can reproduce the same issue with the SoundPool library.
Suggestions:
- use lgMusic for the sounds to play after their loading or use my OpenSL Player library, which is not based at all on SoundPool (it plays only WAV files)
- play your sounds with lgSound only after a user action (in an event).

Thank you for reporting these problems.
 
Last edited:

sterlingy

Active Member
Licensed User
Longtime User
Thanks Inormatix. I will convert my file to a wave and try your OpenSL Player lib.
 

Chrrris

Member
Licensed User
Longtime User
I also had this SoundPool issue in my (in development...) game. I worked around it by creating a sound effects class that loads the main sfx used by the game during app start-up/initialisation. By the time everything else is loaded and the title screen is displayed, all the sound effects are good to go.

I was previously loading the effects each time "Start Game" was selected (and disposing them after Game Over) and they weren't always ready in time for the start of the game. In the end, I figured this was not the ideal way to do it because, as well as the SoundPool issue, it just creates delays during the start of the game while OGGs are uncompressed, etc.
 

sterlingy

Active Member
Licensed User
Longtime User
I was able to prove that the sounds were loaded, so that was not the problem in my case. I think Informatix has it right that there has to be an event triggered by the user before playing the first sound. Using his sound lib did solve this problem.

-S
 

Chrrris

Member
Licensed User
Longtime User
Okay, maybe multiple issues are being discussed here, but soundpool does decompress ogg files asynchronously, so attempting to play a sample too soon after loading it is something that must be avoided with libgdx.
 

Informatix

Expert
Licensed User
Longtime User
Here is the final version of the library. After this 1.0 there will be no new features, no new functions or properties, just bug fixes. This version provides all what you need to create a 2D or 2.5D game and seems to be very stable so I don't feel the need to continue to work on it.

Among new things, I added in this version a profiler and a scene2d debug renderer (see the Scene2D_Table demo) and the possibility to create your own mipmap chain. I also wrote a MipMaps section in the guide to give you some insight about this useful feature (demonstrated by the Filters project).

Now Box2D is isolated from the rest of the C library (.so) so it is possible to create your own "lite" version of the library. To remove the unneeded code, first duplicate the JAR file and open this copy with an archiver (.jar are zipped files).

To remove Box2D:
- remove all libgdx-box2d.so files in the subfolders of "lib";
- remove the folder "anywheresoftware\b4a\libgdx\box2d";
- remove the folder "aurelienribon";
- remove the folder "com\badlogic\gdx\physics".
You'd save about 300 Kb.

To remove Scene2D:
- remove the folder "anywheresoftware\b4a\libgdx\scene2d";
- remove the folder "com\badlogic\gdx\scenes".
You'd save about 270 Kb.

To remove the support for x86 CPU (uncommon in the Android world):
- remove the "lib/x86" folder.
You'd save about 500 Kb.

To remove the bitmap font generator (useless if you don't create fonts from otf/ttf files at runtime):
- remove all libgdx-freetype.so files in the subfolders of "lib";
- remove the file "anywheresoftware\b4a\libgdx\utils\lgFontGenerator.class";
- remove the folder "com\badlogic\gdx\graphics\g2d\freetype".
You'd save about 900 Kb.
 
Last edited:

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

Can you confirm that ScaleBy and ScaleTo as an Actions method works?

I have the following line:
Dim AnimationGoal As lgScn2DAction = Actions.ScaleBy2(2, 2, 3)

And it does nothing, but other Actions, like Fade and MoveTo are working

-Sterling
 

Informatix

Expert
Licensed User
Longtime User
Hello,
ScaleBy and ScaleTo work but you need to set also Transform of the group to True (same thing for rotations).

EDIT: I updated the documentation with this information (in the Widgets section).
 
Last edited:

sorex

Expert
Licensed User
Longtime User
Informatix: funny to read you clean up post now, I checked it out myself 2 days ago and noticed the x86 stuff aswell.

when I removed it the smileyfps app didn't seem to work right. Was under genymotion tho.

there is also an armsomething_v7 there with a few hundred K of data, what is this exactly?

should give it another try tonight.
 

ilan

Expert
Licensed User
Longtime User
hi,

does the libGDX contains the possiblity to control the accelerometer or the gyroscope?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…