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:

alienhunter

Active Member
Licensed User
Longtime User
Hi Informatix,
i used the very first time your library , it is very nice works very well
I want to create a small CAD/CAM app to start with (basic elements> shaperenderer) with your library but i could not find any example of
zooming with Camera As lgPerspectiveCamera.
I went thru all your examples but there is only one with Camera As lgOrthographicCamera
I might not fully understand all libgdx library but i am stuck to go one step forward
thanks AH
 

Attachments

  • 123.jpg
    66.8 KB · Views: 213
  • 124.jpg
    62.2 KB · Views: 226
  • test.zip
    8.6 KB · Views: 246

Chrrris

Member
Licensed User
Longtime User
My first post to this forum, so apologies if this is in the wrong place or anything.

I'm using the libgdx library to write a 2D scrolling shooter and so far it's going really well; I'm loving libgdx and B4a, and the way the library integrates so seamlessly. However, my scrolling level is a tiled map (lgMapTiledMap) and I am stuck on one thing:- I want to have a few animated tiles scattered around the map and I can't work out how to do this at all. The lgMapAnimatedTiledMapTile object appears to have no means of specifying the animation interval or list of animation frames. I am probably overlooking something, or missing something obvious, but I can't figure it out. Is this object missing an Initialize() method, possibly?

The libgdx examples are fantastic and have been a great help to me so far, but there is no example for lgMapAnimatedTiledMapTile and I can't seem to work it out for myself.

Hope you can help!
 

Informatix

Expert
Licensed User
Longtime User
"Zoom" does not mean anything in 3D, that's why there's no function in lgPerspectiveCamera. If you're in the street and notice something interesting in a store, you walk to go closer. It's the same thing for the camera. You move it along one of its 3 axis to move closer. The orthographic camera cannot do that because there's no depth in 2D.
EDIT: you can also alter the size of the viewport to simulate a zoom.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
I want to have a few animated tiles scattered around the map and I can't work out how to do this at all. The lgMapAnimatedTiledMapTile object appears to have no means of specifying the animation interval or list of animation frames.
Exact. These informations are supposed to be stored as properties in the map. Not all map editors are able to generate animated tiles so it would be a good addition to the lib to allow to create these animations at runtime. I will add this to the v1.0 which is going to be released next week.
 

Chrrris

Member
Licensed User
Longtime User
Ah, I see, thanks. I'm using Tiled and it doesn't generate animated tiles -- I will try some other editors. But the ability to create them dynamically in code would be very useful too.

Keep up the great work, Informatix. The combination of B4A and your LibGDX wrapper is awesome. Really looking forward to v1.0.
 
Last edited:

alienhunter

Active Member
Licensed User
Longtime User

thanks for the reply
I altered the viewport with but it works only on "x axis" , hmmm sorry i try to understand your library,
I did a couple of 3D projects in opengl in VB6 and but i want to switch everything in Android and FX (once it is supported ), it is not much difference but for some reason
i got a brainf... on this .
many thanks
 

Informatix

Expert
Licensed User
Longtime User
I did a couple of 3D projects in opengl in VB6 and but i want to switch everything in Android and FX (once it is supported ), it is not much difference but for some reason
i got a brainf... on this .
Here's a simple way of simulating a zoom (replace this function in my ShapeRenderer demo):
B4X:
Sub IP_TouchDragged(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    If Pointer <> 0 Then Return False

    'Zoom in/out
    If ScreenX > LastX Then
        Camera.Translate(0, 0, Camera.Position.Z * 0.06)
    Else
        Camera.Translate(0, 0, -Camera.Position.Z * 0.06)
    End If
    Camera.Update

    LastX = ScreenX
    Return True   
End Sub
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I have an odd situation

I have some text and buttons that are displayed on the screen. I remove the Capture Listener so only the buttons can be touched. Once a button is touched, I add the Listener back to the hosting Stage.

The problem is that there are three lines of text, and when I remove the Listener, the middle line is not displayed. If I don't remove the Listener, everything is fine. I should also add that the line that is not displayed is animated.

Can you think of something that might cause this?

-Sterling
 

Informatix

Expert
Licensed User
Longtime User
No idea. Could you send me an example reproducing this issue?
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I sent the code to you for the above problem. I think I forgot to mention that when you lose a level, i.e. GAME OVER, you have to click on Play Again to see the problem.

That issue aside, could you give some clarity the Asset Manager?

For example, if I use it to load a sound (your example: "Dim mySound As lgSound = AM.Get("audio/bubblepop.ogg")" do I not have to initialize it as I would normally do if not using the Asset Manager so I can then use mySound.play?

Also, in your example, you have the following line: "lGdx.Graphics.ContinuousRendering = False"

How is it that the above line does not disrupt the normal flow of rendering, after the assets have been loaded?

Cheers,

Sterling
 

Informatix

Expert
Licensed User
Longtime User
Informatix,

I sent the code to you for the above problem. I think I forgot to mention that when you lose a level, i.e. GAME OVER, you have to click on Play Again to see the problem.
The problem in your code is that you call HUDStage.Initialize (HUDStage_Init) many times. So you create a new stage with each call. If you want to clear all children, actions and listeners, call the Clear function instead.
In LibGDX (as in many wrappers), the wrapped class is usually instantiated in Initialize (Dim instantiates only the wrapper), that's why calling Initialize many times has to be avoided. As you won't probably be the last to do this mistake, I'm going to protect my code a bit more against multiple Initialize. What do you think is best? Crashing the app to warn the developper or destroying the previous stage and recreating a new one (not my favourite)?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User

The AssetManager initializes all loaded resources, so they are ready to use. After "Dim mySound As lgSound = AM.Get("audio/bubblepop.ogg")", you can call mySound.Play.
In my demo, I produce no visual result so I don't need to render continuously once all resources are loaded, that's why lGdx.Graphics.ContinuousRendering becomes false. If I set it to false before loading my resources, then the Render event would never be called and nothing would be loaded (as the loading is made via the AM.Update call). ContinuousRendering does not stop the flow. It prevents the event from being triggered again.
 

sterlingy

Active Member
Licensed User
Longtime User

The reason I call HUDStage repeatedly is because I have multiple Stages, and for some reason A stage with a Listener on it does not respond if another stage has been initialized after the HUDStage, even though the latter stage has no Listener, or if you remove the Listener from the latter stage. Assuming I am wrong about the problem I just mentioned and that there is a solution to the problem, I think crashing the app to warn the developer is probably the best solution, though destroying the previous stage may prevent less headaches for everyone involved.
 

Informatix

Expert
Licensed User
Longtime User
One stage is enough. You can create different groups in your stage: one for the HUD, one for the moving sprites, one for the menu, etc. Having multiple stages means having multiple batchers for the rendering, which is not very efficient. If you want to keep your existing stages, change Initialize to Initialize3 and share the same spritebatch instance.
I never did a test with more than one stage so maybe there are issues. I will look into that.
 
Last edited:

sterlingy

Active Member
Licensed User
Longtime User
I'm sloe t o having a beta version of my app ready for testing. Once that is finished, I'll break the code while I try to clean it up and make it more efficient.

The reason I have multiple stages is because of Tables. I despise working with Tables in libGDX. Anyway, there are situations where table cells would overlap, instead of monkeying around trying to get my Table Cells exactly where I want them, I just created multiple stages with different tables.
 

Informatix

Expert
Licensed User
Longtime User
Tables are groups. You can have hundreds of them in the same stage, overlapping or not. For now, I see no reason to have more than one stage.
 

sterlingy

Active Member
Licensed User
Longtime User
Tables are groups. You can have hundreds of them in the same stage, overlapping or not. For now, I see no reason to have more than one stage.
Okay, I'll re-code. As you can see, this will be quite the undertaking, but cleaned up, which is better.

Thanks for your help.
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix, I thought I had this figured out, but it is not playing my sound. Here is my code:

B4X:
    Do While AM.Update = True
            Log("Progress=" & Floor(AM.Progress * 100) & "%")
    Loop
   
    'Logs some information about the loaded assets
    Log("------")
    Log("Loaded assets:")
    Dim L As List = AM.LoadedAssetNames
    L.Sort(True)
    For i = 0 To L.Size - 1
        Log("- " & L.Get(i) & " (" & AM.GetAssetType(L.Get(i)) & ")")
    Next
    Log("------")
   
    Dim horseSFX As lgSound = AM.Get("audio/horse_neigh.mp3")
    horseSFX.Play2(1)

The log shows that the sound is loaded, and I don't get any errors.
 

Informatix

Expert
Licensed User
Longtime User
Did you remove Activity.Finish at the end of the demo? Because you cannot play any sound if the activity is finished.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…