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:

Peter Simpson

Expert
Licensed User
Longtime User
I really want to get into the LibGDX library.
I take one look at this library and I think to myself, going to medical college to learn brain surgery would probably be a lot easier

I really have to take a few days to learn the basics one day...
 
Last edited:

inakigarm

Well-Known Member
Licensed User
Longtime User
I really want to get into the LibGDX library.
It I take one look at this library and I think to myself, going to medical college to learn brain surgery would probably be a lot easier
I really have to take a few days to learn the basics one day...


 

walterf25

Expert
Licensed User
Longtime User
Hello everyone, i was wondering if anyone could help me figure something out, i've done libgdx games, but only using Scene2d, now i'm working on a game which uses both Scene2d and Box2d, i've read tons of threads about this issue but don't understand a damn thing, lol.

How can i figure out the coordinates for a physics body and apply a texture to the body, and move the texture to the same position the physics body is moving?

so far I have the texture drawn on the scened2d stage and my physics body but the texture gets drawn far away from the physics body.

Any one?

Thanks,
Walter
 

Informatix

Expert
Licensed User
Longtime User
You have a very simple example provided with the library (Box2D_PhysicsBodyEditorLoader) and I already saw in this forum a more advanced example showing a bottle filled with balls; you should try to find it.
 

wonder

Expert
Licensed User
Longtime User
Hello again Informatix,

Here's a somewhat generic question.
I usually initialize lgdx as a view and handle the "normal" stuff like, panels, labels and so on, inside a timer event. The code goes something like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    (...)

    'Initialize libGDX
    GLView = lGdx.InitializeView("LG")
    Activity.AddView(GLView, 0%x, 0%y, 100%x, 100%y)

    (...)

    Auxiliary_Engine_Stuff.BringToFront 'All the panels, labels and so on...

    Auxiliary_Engine.Initialize("Auxiliary_Engine", 16)
    Auxiliary_Engine.Enabled = True
End Sub

Sub Auxiliary_Engine_Tick
    'Handle "normal" stuff
End Sub

Sub LG_Render
    'Handle graphics, sound, logic, math and everything else that doesn't crash my program
End Sub


As I understood from your tutorial, LibGDX runs on a different thread from the main activity one.
Informatix said:
You cannot use the debugger of B4A with libGDX because most of the code of the library runs in a different thread.
It comes under my impression that everything happens faster inside LG_Render rather than inside of Auxiliary_Engine_Tick, but I don't know if this is only my imagination.


So my question is:
Is there a performance advantage on running more complex mathematical operations, for example calculations between matrices, in the GDX thread?
For example in my Asus tablet, is the code a = ((b * c) / d) being handled by the Quad-core 1.2 GHz Cortex-A7 CPU when running inside the "auxiliary engine",
instead of being handled by the PowerVR SGX544 GPU, if ran inside LG_Render?

I'm sorry if this is a dumb question.
 

Informatix

Expert
Licensed User
Longtime User
I don't understand why you want to use a timer while you have the Render event at your disposal (synchronizing your views with libGDX is probably cumbersome and not reliable at all). The Render event is raised by the OpenGL driver, so it is raised ASAP to feed the hardware with data. If you do nothing, it is triggered at the maximum rate of your display (in most cases: about 60 fps). The timer tick event is not at all in this case and becomes very unreliable when you set a low interval (even if you do nothing).
Your computations in B4A are always done by the CPU. The code of your shaders, on the contrary, is run by the GPU.
 

wonder

Expert
Licensed User
Longtime User
Thank you very much for the explanation, Fred!! I will start using lgdx.CallSubUI() instead and ditch the timers.

Your computations in B4A are always done by the CPU. The code of your shaders, on the contrary, is run by the GPU.
...and this answers my question. Thanks again. Everything's clear now.
 

TheJinJ

Active Member
Licensed User
Longtime User
I was just looking through an old folder of test projects and came across a RUBE to Box2D export I wrote last summer. RUBE is a cool editor that allows you to plot shapes, points etc, you can then export as a json file. Using this in B4J(or B4A if you like) it will create the needed code for use in B4A.
Tested and mostly worked, may be handy for someone

RUBE
 

Attachments

  • Rube_Box2D_Export_v1.zip
    17.3 KB · Views: 196

Informatix

Expert
Licensed User
Longtime User
I can pass the object OK but can't access any of it's properties. I'll have another go tonight when I'm back in. Cheers
I don't understand. If you expect to be able to do something like UserData.Color=... that cannot work because UserData is a generic object. UserData is not of the lgSprite type. You use it to keep a reference to an object (as you do with Tag for your views). If you want to be able to use the stored Sprite, you have to do something like: Dim MySprite as lgSprite = myBody.UserData. So the object gets a type.
 

TheJinJ

Active Member
Licensed User
Longtime User
I was creating a new sprite and making it equal to the userdata as you suggested, I must be doing something daft wrong so I'll have another look.

 

TheJinJ

Active Member
Licensed User
Longtime User
I have a feeling this is something obvious but this throws an error. If I reference the sprite directly it works fine.

B4X:
body0.createFixture(fixtureDef).UserData = image0

B4X:
    Dim MySprite As lgSprite = body0.UserData
    bvec2 = body0.Position
    MySprite.SetPosition(bvec2.x - MySprite.Width /2, bvec2.y - MySprite.Height /2)
    MySprite.SetOriginCenter
    MySprite.Rotation = body0.Angle * lgmu.radiansToDegrees

B4X:
sb.Begin

    MySprite.Draw(sb)

sb.End

null object reference

 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Are you sure that the original Sprite is initialized? and is not destroyed before using it?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…