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:

walterf25

Expert
Licensed User
Longtime User
Informatix, I have figured it out, i did not know I had to add "LG_" in front of the sub name, thanks anyway.

Cheers
Walter
 

Erel

B4X founder
Staff member
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?
I wouldn't call super mario a simple game. Programming a real game requires programming knowledge. You should download the guides, read the tutorials: http://www.b4x.com/android/documentation.html
 

Informatix

Expert
Licensed User
Longtime User
If you compile with the obfuscation mode enabled, you have to place an underscore in your sub name.
There's an example of call to CallSubUI in Scene2D_Touchpad.
 

Informatix

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?
I'm trying to find some time for my own projects, so I don't think I will create new examples and it's very likely that I will be less and less present in this forum for the next months.
 

walterf25

Expert
Licensed User
Longtime User
If you compile with the obfuscation mode enabled, you have to place an underscore in your sub name.
There's an example of call to CallSubUI in Scene2D_Touchpad.

Thanks Informatix!
 

walterf25

Expert
Licensed User
Longtime User
How do we add standard elements like buttons , labels to this kind off application. I tried using CAllSubUI but it only enables me to change title,
and not to load lets say empty layout and add labels that will show OVER libGDX surface...
You have to use the lgscn2dtextbuttons or lgscn2dlabel for that but again, it depends on what you're trying to do, i have not tried adding the normal buttons to the libgdx surface but i'm guessing you can do it by adding the libgdx surface as a view to the activity.

for example:
B4X:
Dim config As lgConfiguration
config.useGL20 = True
dim V As View
V = lGdx.InitializeView2(config, "LG")
Activity.AddView(V, 0, 0, 100%x, 100%y)

give it a try i think it should work.
 

walterf25

Expert
Licensed User
Longtime User
can you post your entire code, is hard to say without looking at the code
 

walterf25

Expert
Licensed User
Longtime User
Hi Frederic, i need your help, i know it might be something simple but i can't seem to figure it out, and i've studied your examples very thoroughly, but can't seem to figure where the problem is, i have a lgscn2dwindow which displays the b4a logo and libgx logo, but for some reason i can't resize those two images to the size i want them, it doesn't matter the size i set they always appear the same size and stretched out, could you maybe point me in the right direction.
this is the code i use to load the images into the window.
B4X:
dim logo1 as lgscn2dimage
Dim logotexture As lgTexture
    logotexture.Initialize("logos\b4alogo.png")
    logotexture.SetFilter(logotexture.FILTER_Linear, logotexture.FILTER_Linear)
    logo1.Initialize4(logotexture, "logo1")
    logo1.pack
    logo1.Width = 18%x
    logo1.Height = 25%y
    logo1.setPosition(20%y, aboutwindow.Height/2)

but this is how the image looks.

any suggestions on how to size the images to my taste, and is there a reason as to why the setsize property doesn't work?

Thanks,
 

mjas

Member
Licensed User
Longtime User
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Hello, that error happens when the button / label overlaps the libgdx surface. In order to capture the event from those elements they must be out of the libgdx surface, or use the equivalents for libgdx: lgscn2dtextbuttons or lgscn2dlabels
 

mjas

Member
Licensed User
Longtime User
Try these: logo1.setSize(18%x, 25%y) or logo1.setScale(scaleX, scaleY)
 

walterf25

Expert
Licensed User
Longtime User
Try these: logo1.setSize(18%x, 25%y) or logo1.setScale(scaleX, scaleY)
that doesn't work, i've already tried that, but i figured it out, what you need to do is when you add the actor to the window like this
B4X:
aboutwindow.AddActor(logo1).Width = 200dip
you can do the same to specify also the height.

thanks
 

Informatix

Expert
Licensed User
Longtime User
I didn't try but I suggest to set minWidth and minHeight to the right dimensions as your Image is placed in a container (in a widget that contains other widgets, the prefered size is set to the min size).
 

maxmolinari

Member
Licensed User
Longtime User
Good evening Mr. Informatix,

I want to write an app where, when I inserted the coordinates of a rectangle (or a room, for example) I can also add the height of this rectangle and then have a parallelepiped that I can rotate within the axis X, Y and Z.

My target is to draw a room that can also have a false ceiling or a floor void, a typical data center, and then put some racks inside of it or something else outside of it next to the walls. Something similar of a small CAD application but not necessary something huge like a real AutoCAD application. Just to draw rooms, nothing more.


Do you think that I can do it using your Library? If you have any other ideas or suggestions, these will be welcome.

Thank you in advance for your support.
With Best Regards,

Max
 

Informatix

Expert
Licensed User
Longtime User
This library has a limited support of 3D objects (mainly by using expert functions) so I don't think that's the good one for your project. You should look at the jPCT-AE library instead.
 

maxmolinari

Member
Licensed User
Longtime User
Thank you Sir for your reply.
I will folllow your suggestion but I will also study your Library to understand the main carachteristics.

Kind regards,
Max
 

Informatix

Expert
Licensed User
Longtime User
New major version

I posted a new version that is a major update. All the code supporting OpenGL ES 1.x was removed because the percentage of devices with only this version is now 0.1%. I added the classes for Decal objects so you can put now your 2D objects in 3D space, and added more than 40 functions and properties.
This is probably my last update. The following versions will just fix bugs.

v0.96:
In this version, I:
- removed all the code supporting OpenGL ES 1.x
- fixed a few bugs
- added new classes for decals (2D objects in 3D space): lgDecal, lgDecalBatch, lgCameraGroupStrategy, lgDefaultGroupStrategy, lgSimpleOrthoGroupStrategy
- added an example for decals
- removed the Mesh example as it cannot work with OpenGL 2 without being rewritten
- added the lgScn2DProgressBar class and modified the Scene2D_TextFieldsAndSliders example to show how to use it
- added the IsInitialized function to a dozen of classes
- added these functions:
lgBox2DWheelJoint: isMotorEnabled
lgFontGenerator: CreateFont5, CreateFont6 (for mip maps and filters)
lgMathGeometryUtils: polygonArea, triangleArea
lgMathMatrix3: getScale, getTranslation, setToRotation2, setToRotation3, setToRotationRad, rotateRad
lgMathMatrix4: det3x3, setToRotationRad, setTranslation
lgMathUtils: isEqual, isEqual2, isZero, isZero2
lgMesh: CalculateRadius, CalculateRadius2, CalculateRadiusSquared
lgScn2DDragAndDrop: SetTouchOffset
lgSprite: SetOriginCenter
- added these properties:
lgBox2DJoint: CollideConnected
lgBox2DDistanceJoint, lgBox2DFrictionJoint, lgBox2DRopeJoint, lgBox2DWeldJoint: LocalAnchorA, LocalAnchorB
lgBox2DGearJoint: Joint1, Joint2
lgBox2DPrismaticJoint: LocalAnchorA, LocalAnchorB, MaxMotorForce, ReferenceAngle
lgBox2DWheelJoint: LocalAnchorA, LocalAnchorB, LocalAxisA
lgMathMatrix3: Rotation, RotationRad
lgScn2DActor: isTouchable
lgScn2DScrollPane: ScrollHeight, ScrollWidth, VariableSizeKnobs
lgScn2DWindow: ButtonTable, Resizable, ResizeBorder, TitleWidth
- renamed the functions Translate -> MoveBy, Rotate -> RotateBy and Size -> SizeBy of the lgScn2DActor class
- removed toScreenCoordinates from lgStage and toWindowCoordinates from lgScissorStack
- removed the yDown parameter from ComputePolygon and ComputePolygon2 in the lgMathConvexHull class
- improved a bit the help text of a few functions
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hi Informatix,

I've been playing around with the Cloney Bird example that Andymc wrote using libGDX & I'm finding that I'm pretty regularly getting a crash when I exit the app using the back key (so UserClosed is being set to True in Activity_Pause). I've tried various things to try to figure out what's causing it, but I'm at a bit of a loss. The unfiltered log looks like this:


I notice that there is a null pointer exception in the render loop & also a fatal exception in GLThread 192. It's making me think that I'm not exiting cleanly, but I have tried call dispose on those libGDX objects that have a dispose method & I still see the issue. I also found that when I did call the various dispose methods, on the occasions that I didn't get a crash, the app would restart with the bitmap font all screwed up. When I removed all the dispose calls & managed to get an exit without a crash, I didn't see the font issue. Any ideas &/or pointers on how to make sure I get a "clean" exit?

Thanks,

- Colin.
 

Informatix

Expert
Licensed User
Longtime User
It seems that you use GenyMotion or a similar emulator. Do you have the same errors on a real device?
The main reason that I know for a crash while exiting is a call to dispose for an uninitialized object. You should check whether the object is initialized before disposing it: if myTexture.isinitialized then myTexture.dispose

It is very important to dispose properly the used resources because, contrary to the data in the Java heap space, there's no garbage collector for the libGDX resources (most of them are stored in the native heap memory).
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…