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:

Asmoro

Active Member
Licensed User
Longtime User

Yes I knew it really sounds stupid, but had a solution for it by now.

But can I ask you another question that may have some `challenge ingredient` in it:

Learning and testing using Andymc cloney bird game I wonder how to code
if a score reach every 50 or 100 another image beside "pipe" will appear, like:

B4X:
If Score>100 Then

............
End If

Thanks for now.

gr.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
You have to use the mod function:
if Score mod 50 = 0 then 'the code after this will run every 50 pts
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi Fred,

I am loading an image using a texture. How do i set the gravity of the image.

Is it a good practice to scale the image to the device height and width and then set it as a background using texture

Or

Is there a way where i can crop the images using LibGDX.

Kindly let me know.

Regards,
Sk
 

Informatix

Expert
Licensed User
Longtime User
I am loading an image using a texture. How do i set the gravity of the image.
I don't have any generic answer to your question as the Gravity setting does not exist outside of ImageViews and I don't know what you want to do exactly. For example, I could suggest to place an lgScn2DImage inside a lgScn2DTable, or to use a texture region.

Is it a good practice to scale the image to the device height and width and then set it as a background using texture

Or

Is there a way where i can crop the images using LibGDX.
I cannot give you a single answer. The visual result is completely different in these two cases (stretching vs. panning). To crop a texture, use a texture region.
 

Douglas Farias

Expert
Licensed User
Longtime User
hi informatix
i m trying to use your examples and i have error on AssetManager
here is the log

in release mode app open and close

in debug show me this error
gnoring event: lg_create. Raised from the wrong thread.

how can i fix this?

B4X:
LogCat connected to: B4A-Bridge: motorola XT1033-359321054369100
--------- beginning of /dev/log/main
libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Ignoring event (too many queued events: CallSubDelayed - UpdateStatus)
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Ignoring event (too many queued events: CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:flm.b4a.testlibgdx
Installing file.
PackageAdded: package:flm.b4a.testlibgdx
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
sensor listener setup
OGL renderer: Adreno (TM) 305
OGL vendor: Qualcomm
OGL version: OpenGL ES 3.0 V@66.0 AU@  (CL@)
OGL extensions: GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_robustness GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_depth_texture_cube_map GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_texture_filter_anisotropic GL_EXT_multisampled_render_to_texture GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_disjoint_timer_query
framebuffer: (5, 6, 5, 0)
depthbuffer: (16)
stencilbuffer: (0)
samples: (0)
coverage sampling: (false)
Managed meshes/app: { }
Managed textures/app: { }
Managed shaders/app: { }
Managed buffers/app: { }
Ignoring event: lg_create. Raised from the wrong thread.
Ignoring event: lg_resize. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
** Activity (main) Pause, UserClosed = false **
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_pause. Raised from the wrong thread.
paused
sensor listener tear down
** Activity (main) Resume **
sensor listener setup
Ignoring event: lg_resize. Raised from the wrong thread.
Ignoring event: lg_resume. Raised from the wrong thread.
resumed
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
** Activity (main) Pause, UserClosed = true **
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
 

Douglas Farias

Expert
Licensed User
Longtime User
B4X:
You will need to run it in Release mode. Until B4A v3.50 the rapid debugger didn't support raising events from other threads.
You will need to run it in Release mode. Until B4A v3.50 the rapid debugger didn't support raising events from other threads.

i m runing at release mode but when open the app close in the same time

my b4a is 3.20 it is the problem?
 

Informatix

Expert
Licensed User
Longtime User
The explanation is given in the post just above yours.
 

Douglas Farias

Expert
Licensed User
Longtime User
Hi again @Informatix
i have buyed the 3.8 i test now and again
in release mode the game run and close at same time
on debug mode now is diferent show me this error now

AssetManager example


 

Informatix

Expert
Licensed User
Longtime User
Hi again @Informatix
i have buyed the 3.8 i test now and again
in release mode the game run and close at same time
I explained in post #208 that nothing visual is produced by this demo as it only loads assets. The output is in the log. So what do you expect?

on debug mode now is diferent show me this error now

As said in the first paragraphs of the introduction to libGDX, which is mandatory to read before using the lib, applications have to be run in Release mode only.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I never tried to add an ad banner in my projects but I suppose it's a panel that you put at the bottom of the screen. I suppose also that you put your LibGDx view just above so what's the problem exactly?
Hi Informatix,

So I found an issue using this approach. On my Galaxy S3, if I create a a LibGDx view that is anything but full screen, it has a negative impact on the frame rate - to the point where it gets very jerky. I create a surface:

B4X:
Dim surface As View

Then initialize it as a LibGDx view:

B4X:
surface = lGdx.InitializeView("LG")

Then add it to my activity, leaving a gap (iHeight) at the bottom:

B4X:
Activity.AddView(surface, 0, 0, 100%x, 100%y - iHeight)

When I do this & then run the app, I find that the frame rate is dropping down into the 30's & 40's. If I add the surface full screen:

B4X:
Activity.AddView(surface, 0, 0, 100%x, 100%y)

I don't see this problem. I don't see the same issue on my Nexus 7, but I think that's because it has a much faster processor.

Thanks - Colin.
 

Informatix

Expert
Licensed User
Longtime User
I can't explain why. I tried to verify that on two of my devices less powerful than a Nexus 7 and was not able to reproduce it. Whatever the screen size or the method of initializing LibGDX (as a view or as a full screen surface), I got the same FPS.

You could try this:
in the Perf_skaters demo, note the FPS with 2000 sprites, then replace this line:
lGdx.Initialize2(Config, "LG")
by:
Activity.AddView(lGdx.InitializeView2(Config, "LG"), 0, 0, 100%x, 90%y)
Do you still notice a FPS difference?
 
Last edited:

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I want to scale a ChainShape, but I can't find a method to do it. I though I'd be able to read each vertex, but have not found out how to read them individually and then scale their position and save them to a new array of vertices or just scale the shape as a whole

Is it possible?

-Sterlingy
 

Informatix

Expert
Licensed User
Longtime User
I have no experience with ChainShapes. My first attempt would be to change the radius of the shape.
 

sterlingy

Active Member
Licensed User
Longtime User
I have no experience with ChainShapes. My first attempt would be to change the radius of the shape.
I resolved my issue as I was able to get the vertices from lgMapPolylineMapObject, however, You might want to look at GetVertex from lgBox2DChainShape. I had an XML error in the editor and couldn't figure out how to use it. The official libGDX docs show it takes an Index and Vertex, but that didn't seem to work in b4a.

~Sterling
 

PaulR

Active Member
Licensed User
Longtime User
Hmmm.... is there any obvious way of using some of the b4a output with apps created with this to load into Eclipse with libgdx and deploy to other platforms?
 

Informatix

Expert
Licensed User
Longtime User
I will fix the documentation for the next version (you pass the index, and you get the result in the 2nd parameter). The help text of Radius needs a fix too (it should be "Gets or sets the radius of this shape.").
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…