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:

Computersmith64

Well-Known Member
Licensed User
Longtime User
Yeah - I use GenyMotion, but it happens more consistently on real devices as well. I will take another look at the disposal of those objects. One more question:

Should I also call the LibGDX Exit method & does the LG_Dispose event ever get called (it doesn't seem to)?

Thanks,

- Colin.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
OK - so I shouldn't call exit myself? Also, should I put the object dispose calls in the Dispose event instead of the Activity_Finish? Oh wait - are you saying that if I call Exit, it will call Activity.Finish?

Thanks - Colin.
 

Informatix

Expert
Licensed User
Longtime User
OK - so I shouldn't call exit myself? Also, should I put the object dispose calls in the Dispose event instead of the Activity_Finish? Oh wait - are you saying that if I call Exit, it will call Activity.Finish?

Thanks - Colin.
It's probably better to call directly Activity.Finish because there's maybe some code added by Erel in the Finish method of B4A (I didn't check). Anyway, in all cases, the Pause event of your app will be raised. In this event, you have to call the Pause method of libGDX that's responsible for triggering the Dispose event (where all your Dispose calls should be made).
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
OK - thanks. I'll give it a try.

- Colin
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hi Informatix,

Is there a way to take a screenshot in LibGDX? I don't see any obvious built-in functionality, so thought that populating an lgPixmap using glReadPixels might be the way to go, however I'm not sure how to convert this to a bitmap so that I can write it out to a file. Or am I going down the wrong track here?

Thanks - Colin.
 

Informatix

Expert
Licensed User
Longtime User

If you want to take a screenshot from within the app, it is a good idea to convert to a pixmap. You can take this Java example as a basis. To save your pixmap to a PNG, you have to use the lgPixmapIO class.
 

ppgirl

Member
Licensed User
Longtime User
Hi Informatix,

Today , Libgdx update to 1.0 ,

Do you have plan to update to Libgdx 1.0 ? We are waiting ...
 

Informatix

Expert
Licensed User
Longtime User
The version number of LibGDX for B4A is independent from the version number of the Java version. I already use the code of the version 1.0 since a few months (the nightly builds). The major differences of the B4A version are:
- not all 3D features;
- no possibility to use your own sprite batcher (who's skilled enough to write one anyway?);
- not all Math classes (no CumulativeDistribution, no DelaunayTriangulator);
- not all widgets for Scene2D (no Dialog, no Tree, no TextArea);
- no viewport class and no skin class for Scene2D;
- no Daydream class.

As I want to stop working on this library, which is complete enough for most needs, I won't add what's currently missing. In the future versions, I will only fix bugs and add things that I need for my own projects (and are of general interest).
 
Last edited:

ppgirl

Member
Licensed User
Longtime User
Hi Informatix,

I try your library , and I find a bug that I am not sure.

lgScn2DImage 's rotate() or rotation has no function.

I use your "Scene2D_DragAndDrop" and add rotate() in TgtDarg() for test . then found rotate() is not function .

Sub DogHouse_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
DogHouse.OriginX =DogHouse.Width /2
DogHouse.OriginY =DogHouse.Height /2
DogHouse.rotate (30)
'Checks whether the source can be dropped
If Source = Family OR Source = Cat Then
DogHouse.Color = DogHouse.Color.RED
Return False
Else 'Source = Dog
DogHouse.Color = DogHouse.Color.GREEN
Return True
End If
End Sub

Thank in advance!
 

Informatix

Expert
Licensed User
Longtime User
You probably make reference to an old documentation. Rotate() has been renamed.
To rotate an actor, you have a property (Rotation) that sets the angle of rotation, and a function (RotateBy) that adds a rotation to the current rotation.
 

ppgirl

Member
Licensed User
Longtime User
You probably make reference to an old documentation. Rotate() has been renamed.
To rotate an actor, you have a property (Rotation) that sets the angle of rotation, and a function (RotateBy) that adds a rotation to the current rotation.

Hi Informatix,

I have try 0.97 library , and the "Rotation" and the "rotateby" have no function too.

Base your example , I add rotate after drag . but I can not see the DogHouse any change.



Sub DogHouse_TgtDrag(Source As lgScn2DActor, Payload As lgScn2DDragAndDropPayload, X As Float, Y As Float, Pointer As Int) As Boolean
DogHouse.OriginX =DogHouse.Width /2
DogHouse.OriginY =DogHouse.Height /2
'DogHouse.Rotation =30
DogHouse.rotateBy (30)
'Checks whether the source can be dropped
If Source = Family OR Source = Cat Then
DogHouse.Color = DogHouse.Color.RED
Return False
Else 'Source = Dog
DogHouse.Color = DogHouse.Color.GREEN
Return True
End If
End Sub
 

Informatix

Expert
Licensed User
Longtime User

I confirm there's a bug. It will be fixed soon. Thanks for the report.
 

Informatix

Expert
Licensed User
Longtime User
In the new version (v0.98), I fixed the bug reported here. It's surprising that I missed that (it's there since many versions). I also added the FrameBuffer class because I realized it's a very important class (to take screenshots for example or to combine sprites into a single texture, which is faster to draw).
 

ppgirl

Member
Licensed User
Longtime User

Hi Informatrix,

Bug fixed , good job , Thanks!

Can we have any light way/tool to warp 3rd SDK? One stop to port Java library .
 

Asmoro

Active Member
Licensed User
Longtime User
Hi Informatix,

I'm trying to use lgMusic class to have a background music and make a loop every time restarting a game level
(use Andymc clony bird libgdx sample)

This is my error notfication:

Parsing code. 0.02
Compiling code. Error
Error compiling program.
Error description: Missing parameter.
Occurred on line: 47
Dim myMusic As lgMusic = lGdx.Audio.NewMusic("bookert.ogg")
Word: )

It's missing an evtPrefix parameter..please explain what I have to look for.

Regards

Note. I even use Dim....As Mediaplayer...still no luck
It was playing the first time the game starts and after restart no response at all.
 

Informatix

Expert
Licensed User
Longtime User
Sometimes I wonder whether some questions are serious or not. You have an error message saying "Missing parameter" and you ask what to do? Then, it's simple: add the missing parameter. This parameter, EvtPrefix, is present in hundreds of functions in LibGDX and in other B4A libraries and is described in the help of the function: prefix of the Completed event. If you don't want to use this event, put an empty string.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…