B4A Library libGDX - Game Engine

Discussion in 'Additional libraries, classes and official updates' started by Informatix, Sep 12, 2013.

  1. Informatix

    Informatix Expert Licensed User


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

    How to make games
    Introduction to the libGDX library
    PacDroid: from scratch to fun

    Take also a look at the Cloney Bird tutorial by andymc.


    Last edited: Jul 18, 2019
  2. NJDude

    NJDude Expert Licensed User

    Very nice, and the performance is also very good, on one of the samples I tried the 3000 flakes and I get very good results.

    Good job man.
  3. tipallandgo

    tipallandgo Member Licensed User

    At last, a libgdx library on b4a! great job! :D
  4. stevel05

    stevel05 Expert Licensed User

    That's great work Informatix, I've not looked at games programming, but I'm sure it will be a huge bonus for B4A programmers that do, and B4A in general.
  5. jmbm

    jmbm New Member Licensed User

    Great job!

  6. Pendrush

    Pendrush Well-Known Member Licensed User

    First of all, thank you for your time and effort to wrap this great lib.
    Is this a bug?

    Dim tIDELoader As lgMaptIDEMapLoader
    TiledMap = tIDELoader.Initialize2(
    Log (TiledMap.Layers.Count)
    For i = 0 To TiledMap.Layers.Count-1
    Log (TiledMap.Layers.Get(i).Name)
    If TiledMap.Layers.Get(i).Name.Contains("Foreground"Then
    End If
    Log (TiledMap.Layers.Get(i).Name)
    don't return any value.
    lib version 0.9
  7. Aleksandr

    Aleksandr Member Licensed User

    How i can use Gestures library with libGDX?
    My app rush in RENDER sub.
  8. walterf25

    walterf25 Well-Known Member Licensed User

    Hi Aleksandr, libgdx already has the gestures class wrappepd, you can use it by defining your variable like this

    Hope this helps!

    Dim gestures As lgGestureDetector
    You get the following subs with it!

    Sub gestures_Fling(VelocityX As Float, VelocityY As Float) As Boolean
    End Sub

    Sub gestures_LongPress(X As Float, Y As Float) As Boolean
    End Sub

    Sub gestures_Pan(X As Float, Y As Float, DeltaX As Float, DeltaY As Float) As Boolean
    End Sub

    Sub gestures_Pinch(InitialPointer1 As lgMathVector2, InitialPointer2 As lgMathVector2, Pointer1 As lgMathVector2, Pointer2 As lgMathVector2As Boolean
    End Sub

    Sub gestures_Tap(X As Float, Y As Float, Count As Int) As Boolean
    End Sub

    Sub gestures_TouchDown(X As Float, Y As Float, Pointer As Int) As Boolean
    End Sub

    Sub gestures_Zoom(InitialDistance As Float, Distance As Float) As Boolean
    End Sub
  9. Informatix

    Informatix Expert Licensed User

    It will be fixed in the next version.

    There's another problem with tIDE: if you can't read a tIDE file ("error parsing file"), add a blank line at the end of the file.
  10. DoogieDog

    DoogieDog Member Licensed User

    Nice work Informatix. I ran the Map_tIDE demo with no issues. I modified the map saved as different name changed the code and got the following error. I did try manually adding a blank line at the end of the files as suggested. Thoughts? Doogie

    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    sensor listener setup
    OGL renderer: Mali-400 MP
    OGL vendor: ARM
    OGL version: OpenGL ES 2.0
    OGL extensions: GL_OES_texture_npot GL_OES_compressed_ETC1_RGB8_texture GL_OES_standard_derivatives GL_OES_EGL_image GL_OES_depth24 GL_ARM_rgba8 GL_ARM_mali_shader_binary GL_OES_depth_texture GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 GL_EXT_blend_minmax GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_rgb8_rgba8 GL_EXT_multisampled_render_to_texture GL_EXT_discard_framebuffer
    framebuffer: (5, 6, 5, 0)
    depthbuffer: (24)
    stencilbuffer: (8)
    samples: (0)
    coverage sampling: (false)
    Managed meshes/app: { }
    Managed textures/app: { }
    Managed shaders/app: { }
    Managed buffers/app: { }
    main_lg_create (B4A line: 49)

    TiledMap = tIDELoader.Initialize2("maps/tide/Map02.tide")
    com.badlogic.gdx.utils.SerializationException: Error parsing file: maps/tide/Map02.tide

    at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:71)
    at com.badlogic.gdx.maps.tiled.TideMapLoader.load(TideMapLoader.java:57)
    at anywheresoftware.b4a.libgdx.maps.lgTideMapLoader.Load(lgTideMapLoader.java:26)
    at anywheresoftware.b4a.libgdx.maps.lgTideMapLoader.Initialize2(lgTideMapLoader.java:21)
    at flm.b4a.libgdxtest.main._lg_create(main.java:443)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.libgdx.LibGDX$LibGDX_Listener.create(LibGDX.java:105)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:330)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1506)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1267)

    Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing XML on line 1 near: <?xml version="1.0" encoding=
    at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:312)
    at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:60)
    at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:64)
    at com.badlogic.gdx.utils.XmlReader.parse(XmlReader.java:69)
    ... 12 more
    android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
    java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    at android.os.Handler.<init>(Handler.java:121)
    at android.app.Dialog.<init>(Dialog.java:107)
    at android.app.AlertDialog.<init>(AlertDialog.java:114)
    at android.app.AlertDialog$Builder.create(AlertDialog.java:913)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.libgdx.LibGDX$LibGDX_Listener.create(LibGDX.java:105)
    at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:330)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1506)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1267)
    ** Activity (main) Pause, UserClosed = true **
    sensor listener tear down

    Managed meshes/app: { }
    Managed textures/app: { }
    Managed shaders/app: { }
    Managed buffers/app: { }
  11. Informatix

    Informatix Expert Licensed User

    Read carefully your error message. It indicates that it doesn't like the UTF8 sequence before "<?xml" ("Error parsing XML on line 1 near..."). This is typical of files edited by hand. Open this file with the notepad and save it with an ASCII encoding.
    As the tIDE implementation in libGDX is buggy, I recommend to use TMX files instead (created with Tiled for example).
  12. Puck

    Puck Member Licensed User

    Hi Informatix.

    I really appreciate your time and effort on all of these libraries you have created for us. I have a couple of questions or requests if I may borrow a few minutes of your time.

    I've been trying to put together a game using box2d physics that I really love. I have the physics part working really well. The problem I'm running into is getting the graphic images tied to the actual bodies.

    I have used your "jbox2d" library first and had my game graphics and logic working really well until I needed to figure out how get the body that is under my finger when I touch the screen. There is no callbacks for the touch from what I can see and no way to make one.

    So I then switched to your libGDX library which I think is fantastic but I ran into another wall. How to associate my 50 images to the 50 bodies I have moving around the screen. The box2d parameters used in libGDX are not exactly the same on a lot of the functions as they are used in your jbox2d.

    So what I am asking is,... are there any examples you may have in b4a code that allows images to "attach" to bodies and to be able to hit one with a touch?

    I have tried to translate some of the hundreds of java samples for libGDX out there but have pulled out most of my hair. (I'm not a java programmer).

    I would really be happy if you have some example code for libGDX for this or if you have some b4a code that shows how to hit a body with a touch in jbox2d. One or the other would be really cool.
    Blanko likes this.
  13. Informatix

    Informatix Expert Licensed User

    So it seems that you didn't really look at my examples. The Web example of Jbox2d and libGDX shows how to detect what body is touched (but I recommend with libGDX to set a regular listener to an Actor instead). And the PhysicsBodyEditorLoader example of libGDX displays a texture for each body.
    Drawing a image where is a body is nothing else than drawing an image where is this body, with the body size and angle. I can't see where lies the difficulty.
  14. Puck

    Puck Member Licensed User

    The difficulty lies in that with jbox2d, I was using your accelerated surface to do the drawing of the objects which doesn't translate over to sprite batching or sprites in general. In libGDX, all the java examples suggest to use sprites with spritebatch. I was having trouble trying to translate the java code into b4a code.

    As a physics animation newbie just getting into the physics programming, there is a lot of info to absorb and I have absorbed a lot but when things don't match up well between libraries, it just seems we go through one little issue after another.

    I had loaded all of the examples but didn't study the code of all of them. I was judging if they did what I needed by the graphics alone and didn't realize the web demo had the body touch working (my oversight). I also did not mess with the PhysicsBodyEditorLoader since the name threw me off a bit thinking it was just an editor that I didn't need to use right now.

    There is a bit more to it than just drawing an image where the body is though. For someone like you, it may be super easy but people like me are still figuring this out. The coordinates of the image use a different mapping system than the BOX2d meters system as in your jbox2d examples. I had trouble translating that code over to libGDX since some of the commands are a bit different. Keeping the two married together seems to be the hardest part. Some said to use body.userdata to save the sprite objects but I had issues with that even. I did however come up with a conversion that seems to work between the two and I'm good on that now.

    You don't know how much I appreciate your help. You have opened my eyes and added a whole lot of clarity to my situation. It's guys like you that make the coding in b4a so much easier and fun. You are a legend here and your willingness to help others goes beyond what anyone would normally expect. Thank you so much for your libraries and help Informatix! Please, keep up the great work, for all of our sakes :)
  15. walterf25

    walterf25 Well-Known Member Licensed User

    Hi Puck you can also take a look at one of my examples, i'm new at libGDX also, and so far i'm loving it, I believe this library is the best one so far as far as gaming goes, it is just amazing the stuff you can do with it

    Anyhow check out this example.
    https://dl.dropboxusercontent.com/u/82367588/Physics Loader libGDX_Updated.zip
    Informatix likes this.
  16. Puck

    Puck Member Licensed User

    I have a tear of joy in my eye :) My god man, you have every single one of the things I have been trying to do covered in this code. The physics matched to the sprite batching and more. I can't wait to get home after work and start coding since you have all of the issues figured out. This is more than I could have ever asked for. I'm lov'n the libGDX library. Thank you so much walterf25 and also to Informatix for making this great library available to us.
  17. walterf25

    walterf25 Well-Known Member Licensed User

    I'm glad you found what you were looking for, believe me this library is awesome!
  18. Informatix

    Informatix Expert Licensed User

    Three of the Accelerated Surface examples (Perf_...) have been ported to libGDX so you have concrete examples of the translation between the two libraries.

    Post the code here and I'll explain how to convert it.

    My opinion is that every Box2D object should be created with this editor and loaded with lgBox2DBodyEditorLoader.

    All sizes and positions are defined in meters in my Jbox2D examples. And the conversions between the world coordinates, in meters, and the screen coordinates, in pixels, are done with getWorldToScreen and getScreenToWorld. Not very complicated.
    With libGDX, it's even easier because you don't have to convert anything, thanks to the viewport. It's explained in the camera chapter of the tutorial.

    Post the code and I'll explain.

    What issues?

    Thanks for the compliment, but I'm just a professional. I write code since 1981 and I produced/contributed to hundreds of projects, so I have no real merit. In my professional world, I'm an average Joe, but in a forum where there are a lot of beginners and semi-pro, it's easy to be considered as an expert. In France, we have a proverb for that:
    Au pays des aveugles, les borgnes sont rois (in the land of the blind the one-eyed man is king).
    Computersmith64 likes this.
  19. Informatix

    Informatix Expert Licensed User

    Thank you, Walter, for your examples and your help during the beta test.
  20. Laurent95

    Laurent95 Active Member Licensed User

    [quote="Informatix, post: 193216
    Au pays des aveugles, les borgnes sont rois (in the land of the blind the one-eyed man is king).[/quote]

    Hello all,
    If Informatix allow that, "one eyed man, but which eye" ;-). (pas persuadé que l'humour français sonne bien en anglais)
    Just one question about the example not commented in the forum precendently. Can we have more explanation about the spot light on the screen, even if playing with shaders is a very not easy. This effect is wowwwww. Thanks by advance.
    Best regards (et chapeau Informatix, comme on dirait ici :) )
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice