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
Is there something that would be limiting my Box2D bodies velocity? Everything was moving just fine, and now no matter what I do now, everything is moving at nearly the same speed, and slower than I want.

I read that there is a constant set called "b2_maxTranslation"

This problem has most likely occurred because I got rid of the scale on the tiled map. In order to make that work, I had to scale all of the Box2D bodies up, and I use zoom to set what's seen on the screen. Incidentally, this did not fix the rendering artifacts.

-Sterling
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
You should try to fix your problems one by one and proceed by steps. I'm a bit surprised that you try to render particle effects or a score while you're still not able to render properly the main graphics of your game. You should comment out all this premature stuff and focus on the first steps: rendering your tile map and moving basic objects on screen without issues.
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix, I do try to fix my problems one by one, but sometimes, by doing one thing, it effects another, such as the score bar. Also, after hammering away at a problem, if I don't get it resolved, then I step away for a while, as sometimes I find a solution while doing something else, whether it's coding or going for a walk.
 

Informatix

Expert
Licensed User
Longtime User
As there's obviously a problem with tiled maps when zooming, I investigated the issue and talked with some of the developers of libGDX. Good news! I have an answer and a fix for you: it is due to rounding issues introduced by the texture filtering and can be fixed by using the tiled map packer (see my tutorial). It adds padding and edge to your textures.
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Hi Frederick, i came across another issue while developing my whack a bieber game, i'm trying to implement a countdown timer, i've copied an example done by Erel here, the problem is that the app crashes sometimes, not all the time, and when it crashes i receive this error.

i know it has to do with the timer i'm using, but i don't know why, is there a different way that this can be dealt with in Libgdx?

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User

Frederick, disregard that issue, i decided to implement the countdown timer inside the LG_Render sub, I know that LibGDX has a timer method in the Utils class, but i don't think you wrapped it, anyhow, the way i fixed this issue is by using the lgdx.Graphics.Deltatime property inside the Render sub.
I initialize a variable with an float of 60 and then subtract 1 each iteration inside the LG_Render sub. Below is the code i use, i've timed the countdown timer with a real clock and it seems pretty accurate, haven't been able to measure the exact accuracy but it works for my purpose.

If you have any other suggestions on how to accomplish this i'm happy to hear.

B4X:
    If timeflag = True Then
    temptime = temptime - lGdx.Graphics.DeltaTime
    'Log(Round(temptime) & " " & "seconds have passed")
    Dim second As String
      second = Round(temptime)
      time.text = second
    If temptime <= 0 Then
    timeflag = False
    temptime = 60
    If scorecount > 500 AND scorecount < 700 Then
    GAME_STATE = GAME_PASS
    scorescreen.CreateScoreLeve(stage, lGdx, 80%x, 80%y)
    Else
    GAME_STATE = GAME_OVER
    End If
    End If
    End If

Hope this code is not causing any other issues, so far i've tested it and it works fine, my app doesn't crash anymore.

Cheers,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Hi Frederick, I would like to know if you know anything about this problem i'm having, i had a friend of mine create some images for my game, but he created them with a 32 bit depth resolution, i have tried to load these images and my program crashes of course complaining that it can't load the image, if i convert those images back to 8 bit resolution it works fine, is there a way to load a 32 bit depth resolution image that you're aware of, i did some research in the libgdx forums and google, but couldn't find anything conclusive, hope you can give me some insight on this problem.

thanks,
Walter
 

Informatix

Expert
Licensed User
Longtime User
32 bit PNGs are fine for libGDX. It's what I use and what you should use too. Are you sure of the format of the original files?
 

walterf25

Expert
Licensed User
Longtime User
32 bit PNGs are fine for libGDX. It's what I use and what you should use too. Are you sure of the format of the original files?
Hi Frederick the images were designed using flash and the are 32 bit PNGs I get an error when I run the app.
 

strat

Active Member
Licensed User
Longtime User
I wrote a simple game by using Libgdx and imported Admob banner ad library but it doesn't show banner. I wonder if it is possible or not.
 

noclass1980

Active Member
Licensed User
Longtime User
I'm glad you found what you were looking for, believe me this library is awesome!
Hi,

Informatix suggested I contact you for advice. Could you look at this question

http://www.b4x.com/android/forum/threads/rotate-body-with-libgdx.37819/#post-223975

How do I rotate the bottle and keep the balls inside until they naturally pour out? As you will see in the programme, the Transform2 (Line 160) provides the smooth rotation that I want but breaks the contacts. Informatix suggested a mouse-Joint (?). Any suggetsions. Thanks in advance.
 

strat

Active Member
Licensed User
Longtime User
I never tried to add an ad banner in my projects but I suppose it's a panel that you put at the bottom of the screen. I suppose also that you put your LibGDx view just above so what's the problem exactly?

The problem is exactly other Android objects don't show on the LibGDX surface. (i.e. panel, imageview). I added a panel at the bottom of the screen and tried to draw something but it is not shown. There is no error but nothing appears.
 

strat

Active Member
Licensed User
Longtime User
Informatix, Thank you for interesting but it looks like that I can't do it without your help.
This is my Admob import code :
B4X:
Activity.AddView(AdView1, 0dip, Activity.Height-50dip, 320dip, 50dip)
......
.....
AdView1.LoadAd
AdView1.BringToFront



And when drawing background using LibGDX, I use this code :

B4X:
space=50dip
....
....

Batch.Begin
....
....
Batch.DrawTex3(tex1, 0, space, lGdx.Graphics.Width, lGdx.Graphics.Height-space, xBkGd,NbOfRepetitionsY, xBkGd+NbOfRepetitionsX, 0)
....
Batch.End


I try to add space at the bottom of the screen but LibGDX draw full screen.
 

Informatix

Expert
Licensed User
Longtime User
You have to create a libGDX VIEW (InitializeView). This is done many times in my examples.
 

strat

Active Member
Licensed User
Longtime User
Using Libgdx View I solved the problem. Thank you very much Informatix.
 

walterf25

Expert
Licensed User
Longtime User
Hi Frederick, i'm trying to use the "CallSubUI" method in my game but it doesn't seem to be working, can you maybe look into this, this is my code
B4X:
If scorecount > 500 Then
    GAME_STATE = GAME_PASS
    lGdx.CallSubUI("LoadInterstitial", Null)
end if
I'm calling this inside the LG_Render event, i've tried calling from other places also and it still doesn't work, am I missing something?

Please let me know!

thanks,
Walter
 

Douglas Farias

Expert
Licensed User
Longtime User
informatix can you post a simple game like same: flappy birds or super mario using your library?
i m not programer and i like your exemples, it works in my all devices. can you make a simples game using your lib
same mario or flappy birds?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…