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
The latest release fixes a serious bug with the listeners of Scene2D, allows to set the playback position and get the duration of your music streams, and separates clearly the color of the text in cache and the color of the new text in the lgBitmapFontCache class (depending on where you placed your "Color =", you will have to replace it by SetColors() to get the same result). You can also access now to the loading parameters of TMX maps and to the gesture detector settings.
I added a small example (Filters) to show you the effect of using a Nearest, Linear or MipMap filter for your textures. "Nearest" is the quickest but is visually poor. Linear is good but not as perfect as MipMap. The drawback of MipMap is the creation of a mipmapping chain of images increasing the memory consumption. For more information, read this.
I changed also the Initialize function of lgScn2DSelectBoxStyle to add parameters for the ListBox style and ScrollPane style because they are mandatory.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
I tried to find a solution for a problem submitted last month (endless scrolling for tiled maps) but I didn't find anything elegant that works in most cases (scrolling in all directions) for now. I have a last idea to try but I won't work again on libGDX before a few weeks (I need time for a lot of other things) so don't expect anything soon. In the meanwhile, using a texture and the method shown in the Perf_skaters example is a very simple and perfectly working solution. Alas it's not ideal for the memory consumption as you have a very big texture in memory.
 

Informatix

Expert
Licensed User
Longtime User
What are your thoughts?

A very important thing to keep in mind is that I am not an experienced user of libGDX (probably the most experienced user in the B4a forum but my knowledge is a bit poor). Wrapping a library and knowing how to use it at its best are two different things. I struggle with the same issues that you. My main advantage is that I can change the source code.
In my current project, I decided to use only one activity (because I cannot share the same libGDX object among different activities). So I use the screen manager and each screen is put either in a code module (when it contains "static" code that I want to reuse elsewhere) or in a class (when the screen creates objects in the game like cards or actors). The main module is for the main screen (where the player spends most of the time). I could organize my code differently (with more classes) but it's enough clear for me.
 

Informatix

Expert
Licensed User
Longtime User
i did struggle a bit in placing the background actors and the main actors in the right zindex order

You have AddActorAfter, AddActorAt and AddActorBefore to define exactly where each actor has to be placed (you can call these functions for the stage by using its Root property). You can also set the z-index property to 9999999 to move the actor to the front or 0 to put it in the background.


In fact, it's a horrible bug that I just detected two days ago. It is there since the first version. Sorry.

i'am aware that this requires a lot of work

You have no idea.
When I decide to update libGDX, I count in days, not in hours of work. For the new version, I modified more than 100 classes.


AFAIK, the Perlin and Simplex noise generators are not used for that (their main use is to generate textures and height maps) but that's far from being a stupid idea. Tell me if you succeed in making this effect with a noise.
That reminds me that I have an unreleased library that generates another kind of noise (diamond square) but, as I'm a bit too busy currently, there's no example and that's why it is only on my hard disk.
 
Last edited:

walterf25

Expert
Licensed User
Longtime User

I did tried all those methods before, but none of them seems to work the way they're supposed to, and I also tried playing with the z-index property but i did not obtain good results either, however i have all that working now, i just placed each actor in the physical order they're supposed to be.

In fact, it's a horrible bug that I just detected two days ago. It is there since the first version. Sorry.

Will this be fixed in the coming version?



I've read a post where a guys actually makes the effect i'm looking for with the Perlin noise algorithm, the post is here, i wouldn't know where to start with that but i will continue to search other methods and let you know if i get this to work as well.

Another question, i'm trying to add some particle effects on the game i'm creating, and it seems to work, but since i'm using SCene2d, i can't seem to bring forward the particle effect, the particle effect is always behind the actors and the background. I know you are not an expert with libgdx, but if you can think of any ideas on how to accomplish this please let me know.

Thanks,
Walter
 

Informatix

Expert
Licensed User
Longtime User

I use them also and I did not notice anything wrong with them. Maybe the following code will help you to understand what does AddActorBefore (variable names are self-explanatory):
B4X:
public void addActorBefore (Actor actorBefore, Actor actor) {
        actor.remove();
        int index = children.indexOf(actorBefore, true);
        children.insert(index, actor);
        actor.setParent(this);
        actor.setStage(Stage());
        childrenChanged();
}

Will this be fixed in the coming version?

Please read the changelog in post #1 and the post #121. It's written in the first sentence.


In this post, I agree with the sentence: "But I found using interpolation between values is less computationally intensive and can be just as effective." Generating a noise is slow.


I have to see the code to say something. To draw your particles, do you use the Spritebatch of the stage or a dedicated one? Do you place the drawing function before or after the call to Stage.Draw?
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I noticed something interesting about the rounding issue with the tiled maps. My app has always been locked in Landscape mode, and as you know, I have the rendering anomalies, but I locked into Portrait mode, and the problem went away. I don't know if this would always be the case, but thought I'd report it.

Cheers,

Sterling
 

Informatix

Expert
Licensed User
Longtime User
On your device, are the dimensions even numbers in portrait mode and odd numbers in landscape mode? Did you try with different devices?
 

sterlingy

Active Member
Licensed User
Longtime User
On your device, are the dimensions even numbers in portrait mode and odd numbers in landscape mode? Did you try with different devices?
I've been testing on a Nexus 7 2013, which is 1920x1080. However the problems does still persist on my older Nexus 7, which I believe is 1280x805.
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

Can you think of a reason that a Particle Effect won't render? I copied your code exactly as you have it in the example, and I have it as the last thing rendered. I don't get any errors, but nothing displays.
 

sterlingy

Active Member
Licensed User
Longtime User
B4X:
    Dim Batch As lgSpriteBatch

.
.
.
    Batch.Initialize
.
.
.
    'Loads the four particle emitters
    Effect.Initialize
    Effect.Load(lGdx.Files.internal("particles/particles.p"), lGdx.Files.internal("particles"))
    Dim L As List = Effect.Emitters
    For i = 0 To L.Size - 1
        Dim Emitter As lgParticleEmitter = L.Get(i)
        Log(Emitter.Name & " emitter loaded")
    Next

    'Sets a random value for the wind of the smoke emitter
    Dim Wind As lgParticleScaledNumericValue
    Wind = Effect.FindEmitter("smoke").Wind
    Wind.Low = Rnd(-10, 10)
    Wind.High = Rnd(-60, 60)
    Wind.Active = True

    'Sets the position of emitters
    Effect.SetPosition(lGdx.Graphics.Width / 2, lGdx.Graphics.Height / 2)
    Effect.Start
.
.
.
    Batch.ProjectionMatrix = Camera.Combined
    Batch.Begin
        World.GetAllBodies(tmpBodies)
        Dim tmpBody As lgBox2DBody
        For i = 0 To tmpBodies.size -1
            tmpBody = tmpBodies.Get(i)
            Dim tmpUD As imageType

            If tmpBody.UserData <> Null AND tmpBody.UserData Is imageType Then
                tmpUD = tmpBody.UserData
                If tmpUD.mathItem <> "mapEdge" Then
                    carSprite = tmpUD.thisSprite
                    carSprite.SetPosition(tmpBody.Position.x - carSprite.Width / 2, tmpBody.Position.y - carSprite.Height / 2)
                    carSprite.Rotation = tmpBody.Angle * (180/cPI)
                    carSprite.Draw(Batch)
                End If
            End If
        Next       
        Effect.Draw2(Batch, lGdx.Graphics.DeltaTime)
    Batch.End
    Renderer.render(World.InternalObject, Camera.Combined)
    HUDStage.Act
   
    mapStage.Draw
    HUDStage.Draw

I'm not sure which spriteBatch I'm using. I didn't know there was more than one.
 

sterlingy

Active Member
Licensed User
Longtime User
According to the SetPosition line, it should be in the middle of the screen
 

sterlingy

Active Member
Licensed User
Longtime User
Problem solved. the position needs to use World coordinates, not screen coordinates. Explosions comin' up!
 

sterlingy

Active 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.
 

walterf25

Expert
Licensed User
Longtime User

Hi Frederick, i managed to create the camera shaking effect after an explosion, i'm using sinewaves to make the screenwave move up and down and side to side, it looks very good.
I'll post the code later so that other can use it if they need to.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…