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:

Informatix

Expert
Licensed User
Longtime User
I added a new demo to SpecialFX : Hue_Saturation. It's a better version than the one I sent to you, written entirely in B4A. It is much quicker (x10).
 

wonder

Expert
Licensed User
Longtime User
I added a new demo to SpecialFX : Hue_Saturation. It's a better version than the one I sent to you, written entirely in B4A. It is much quicker (x10).
Fantastic! Thank you so much, once again!
So it doesn't contain any in-line Java code now?
 

SSDM71

Active Member
Licensed User
Longtime User
Hi,

today I have tried to use for the first time this game engine and with the following code I have some problem:

B4X:
Sub Globals
...
      Dim const nARMI As Byte = 1
      Dim img(nARMI,4) As lgTexture
...
End Sub

...

Sub LG_Create
...
For i=0 To nARMI-1
    For t=0 To 3
        Dim str As String = GetNAMEfromID(i)&(i+1)&".png"
        img(i,t).InitializeWithFile(lgdx.Files.internal(str))
    Next
Next
...
End Sub

And return an error on this line of code:
B4X:
img(i,t).InitializeWithFile(lgdx.Files.internal(str))

The error is:


What is my mistake?

Thanks
 

Informatix

Expert
Licensed User
Longtime User
As said by the error message, Razzo1.png has not been found. You should avoid uppercase letters and use only lowercase.
 

holdemadvantage

Active Member
Licensed User
Longtime User
Sorry for noob question (i'm starting now with libgdx).

My problem is to rotate a texture canvas on itself (every frame i need to rotate 2 degrees) the rotation center is the center of the texture

I tried with Batch.DrawTex5 but all i get us to rotate whole texture around a center ouside my image, is there a way to rotate txture around its own center point?

Tnx in advance
 

Informatix

Expert
Licensed User
Longtime User
Use a lgSprite object. By default, the sprite origin is set to the center.
 

holdemadvantage

Active Member
Licensed User
Longtime User
Use a lgSprite object. By default, the sprite origin is set to the center.

Tnx Informatix for this input, it works with this code if i load a bitmap from assets

B4X:
    Textures1.Initialize(lGdx.Files.Files.internal("center1.png"))

    pallacentrale.InitializeWithTexture(Textures1)
  
    pallacentrale.SetSize(60%x, 60%x)
pallacentrale.SetOrigin(50%x, 50%y)

Now the problem is when i want to rotate a bitmap drawed on a canvas (bitmapmutable>draw> result in canvasvariable.bmp )
I can't figure out how i can initialize Textures1 with my bmp (and not from an assets file)...
Tnx to everyone who can give me a help
 

Informatix

Expert
Licensed User
Longtime User
If you use libGDX, there's no need for a canvas or for bitmaps. Moreover bitmaps are not compatible and have to be converted (bitmap -> byte() -> pixmap -> texture). So, if you absolutely need to use canvas and bitmaps, forget libGDX. You're probably not making a game, so for other uses, like image processing, you should stay with Accelerated Surface (much faster than the canvas and with more possibilities) and bitmaps.
 

holdemadvantage

Active Member
Licensed User
Longtime User
I notice that with Accelerated Surface (gameview) my bitmaps are loose quality and also drawing rectangle lines and so on cause very poor quality so i try libgdx
 

Informatix

Expert
Licensed User
Longtime User
I notice that with Accelerated Surface (gameview) my bitmaps are loose quality and also drawing rectangle lines and so on cause very poor quality so i try libgdx
There's no reason for that in "Accelerated Surface" (which is not Gameview and doesn't use it). Do you set the filter parameter to True when you load your bitmaps with LoadScaledBitmap or when you draw your shapes?
 

SSDM71

Active Member
Licensed User
Longtime User
I've a problem to read the pixels

I try this code to read all pixels of the screen:
B4X:
Dim buf() As Object
Dim pix as Pixmap
GL.glReadPixels(0,0,100%x,100%y,pix.GLFormat,pix.GLType,buf)

But It give me an error "incompatible types: Object[] cannot be converted to Buffer" and I don't know how read the pixels. I don't understand which type of variable I have to use that matches with java.nio.Buffer

I do this because I want take a screenshot with pixmap and write that with pixmapIO, if there are some examples in B4A, it's a good thing

thanks,
 

Informatix

Expert
Licensed User
Longtime User
Look at the FrameBuffer demo.
 

SSDM71

Active Member
Licensed User
Longtime User
It give me the same error:

B4X:
Dim pix As lgPixmap
Dim buf As lgFrameBuffer
GL.glReadPixels(0,0,100%x,100%y,pix.GLFormat,pix.GLType,buf)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…