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:

ilan

Expert
Licensed User
Longtime User
and how? how do i declare it? and how do i use it? do you have a simple project or anything else that can explain it to me? like the jumping smiley example of erel.
 

Jaames

Active Member
Licensed User
Longtime User
and how? how do i declare it? and how do i use it? do you have a simple project or anything else that can explain it to me? like the jumping smiley example of erel.
In the Activity_Create you set the configuration like this :
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Initializes libGDX
    Dim Config As lgConfiguration
    Config.useAccelerometer = True
    Config.useWakelock = True
    lGdx.Initialize2(Config,"LG")
End Sub

and in the update method of libGdx (or in the Rende method) you read accelerometar inputs like :
B4X:
'this is just to show where to read inputs, it's a bit complicated than this
someSprite.position.set(lGdx.Input.AccelerometerX, lGdx.Input.AccelerometerY)
I assume that you declared in the sub Globals your libgdx like :
B4X:
Dim lGdx As LibGDX
 

ilan

Expert
Licensed User
Longtime User
wow thanx, so if in need to move the lgtexture i just draw it with the new calculated "lGdx.Input.AccelerometerX,...Y" parameters.

should not be so hard to do, thanx a lot Jaames i will try it when i get home
 

Informatix

Expert
Licensed User
Longtime User
The PacDroid demo and its tutorial shows and explains this.
 

notedop

Member
Licensed User
Longtime User
Awesome library, i've been playing around with it for some days now with some nice results.
Had some struggles in the beginning however there are a lot of docs and tutorials available for the java version.
With some logic applied the tutorials are portable to B4A code.

Thanks for porting this to B4A!
 

notedop

Member
Licensed User
Longtime User
Offcourse, for my investigation on Sprites, i've used :
https://github.com/libgdx/libgdx/wiki/2D-Animation

https://github.com/libgdx/libgdx/wiki
This is basically the wikipedia for libgdx.

In addition the youtube tutorials from Dermetfan are very usefull. I've used them to get more understanding on what is possible with Tiled maps. If you go to his channel, you'll find more workshops on Libgdx.
https://www.youtube.com/user/dermetfan

Beside these, I keep going back to the examples provided with the posts from @Informatix and his extensive explanations. (see Original post/thread starter)
 

notedop

Member
Licensed User
Longtime User
How are TiledMaps rendered? Are all tiles rendered or only the ones which are within the camera view?
I'm trying to understand if I would generate a huge map in Tiled, how it will affect performance.

The idea is to create an horizontal scrolling map, moving the camera horizontally.
Offcourse I don't want the level to be done in 30 seconds meaning the level should be rather wide.
 

Informatix

Expert
Licensed User
Longtime User
Only visible tiles are rendered. Having a very small map or a huge map is the same. Only the number of visible tiles at a given time matters.
 

notedop

Member
Licensed User
Longtime User
I'm unable to set the position of a lgbox2dcircleshape which has been loaded from a tiled map.
I've used log to debug and noticed that there is no effect whatsoever using the Set or Set2 of the lgbox2dcircleshape function.

B4X:
        Dim ObjCircle As lgMapEllipseMapObject = Maps.Layers.Get2("ObjTest").Objects.Get(i)
        'ObjCircle.Ellipse.Set(ObjCircle.Ellipse.x*scale,ObjCircle.Ellipse.y*scale,ObjCircle.Ellipse.width*scale, ObjCircle.Ellipse.height*scale)
       
        Log("Object Circle: X-" & ObjCircle.Ellipse.x & " - Y: "  & ObjCircle.Ellipse.y)
       
        Dim v As lgMathVector2
        V.Set(ObjCircle.Ellipse.x*scale, ObjCircle.Ellipse.y*scale)
        Log("Vector: " & V)
           
        Dim CircleShape As lgBox2DCircleShape
        CircleShape.Radius = (ObjCircle.Ellipse.height/2)*scale
        CircleShape.Position.Set2(V)
'        CircleShape.Position.x = ObjCircle.Ellipse.x*scale
'        CircleShape.Position.y = ObjCircle.Ellipse.y*scale
        Log("Scale=" & scale & " Shape Circle: X-" & CircleShape.Position.x & " - Y: "  & CircleShape.Position.y)

Below is the Log output, which shows that the Set function did not have effect.
Am I missing a step here?

B4X:
Object Circle: X-27790.69921875 - Y: 224
Vector: [416.86047:3.36]
Scale=0.014999999664723873 Shape Circle: X-0 - Y: 0
 

Informatix

Expert
Licensed User
Longtime User
A shape is not what you think. You should read a tutorial about Box2D, like this one.
 

notedop

Member
Licensed User
Longtime User
Circle.Position is the position relative to the body. Position of the body should be set in the Bodydefinition, which should position the shape correctly.
Right?
 

notedop

Member
Licensed User
Longtime User
My emitters load very large. There's no way to set a scale to the Effect or the Emitter, though I do see lgParticleScaledNumericValue, but can't figure out how to use it.

Can you share/advise the settings you've used to solve this within the particle editor?

Edit: Nevermind, i got it. Scale the size and velocity in the particle editor. Use the Pix2Met value in the editor properties to make particle effect better visible for further editing.
 
Last edited:

wonder

Expert
Licensed User
Longtime User
Hello again,

A few weeks ago while reading one of the few libGDX threads, I encountered a post that mentioned some constrains to the texture size.
It should be a multiple of something or something like that.

I have no idea where I read it anymore, so please, if anyone knows what I'm talking about, point me in the right direction or post a short explanation to this matter.

Many thanks in advance!!
 

Informatix

Expert
Licensed User
Longtime User
If you don't use mipmapping, your textures can have any size or ratio. For mipmapping, their size must be a power of two (e.g. 512x512, 1024x1024).
 

wonder

Expert
Licensed User
Longtime User
Thank you!!! I was looking for that info!

Another question if I may... Is there any way to limit the speed of the libGDX? Not the animation speed, but the engine speed itself.
Although my project runs quite well on all emulators and devices I tested so far, I'm having a hard time with an HTC M7, it runs too fast.

I managed to create a "speed limit" myself but I'm not entirely happy with the results.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…