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:

fanfalveto

Active Member
Licensed User
Longtime User
Ok,this two files are into Files folder.
And yes the problem is in juego when return only from puzzle2
 

Attachments

  • Files.zip
    286.1 KB · Views: 264
  • Files2.zip
    258.5 KB · Views: 279

fanfalveto

Active Member
Licensed User
Longtime User
the problem is into "juego","Sub LG_Render","Effect.Draw2(Batch, lGdx.Graphics.DeltaTime)".With "Batch",i quit the effect and this "batch" but crash anyway later in other "Batch".
 

walterf25

Expert
Licensed User
Longtime User
the problem is into "juego","Sub LG_Render","Effect.Draw2(Batch, lGdx.Graphics.DeltaTime)".With "Batch",i quit the effect and this "batch" but crash anyway later in other "Batch".

This is how i render my particles in my wallpapers

B4X:
particletexture.Initialize("particle-star.png")
particlesprite.InitializeWithTexture(particletexture)
  particleflip.Initialize
    particleflip.Load(LW.Files.internal("data/butterfly_tail.p"))
    particleflip.sprite = particlesprite
    particleflip.SetPosition(width1/2, height1/2)
    particleflip.Start

then on the Sub LG_Render sub i do this

B4X:
particleflip.Draw(batch)

don't forget to update the particle in the render sub like this

B4X:
particleflip.Update(LW.Graphics.DeltaTime/1.6)

Hope this helps.
Cheers,
Walter
 

fanfalveto

Active Member
Licensed User
Longtime User
I've solved it by making a small trap, ending the activity and opening it again. I do not like, but it is what it is.
Thank very much you to all.
 

Informatix

Expert
Licensed User
Longtime User
I've solved it by making a small trap, ending the activity and opening it again. I do not like, but it is what it is.
Thank very much you to all.
In Juego.bas, why "Batch.Dispose" is commented out? And where's the call to Dispose() for all the particle effects (bomb, bomb2, effect) and music (soni)? Since the "soni" objects are in fact sounds and not music, you should use lgSound, not lgMusic.

I don't understand the usefulness of the Timer in your code. Use the render event instead.
 

tboy

Member
Licensed User
Longtime User
Informatix,

Thank you for your amazing work, this is a great addition to B4A.

 

strat

Active Member
Licensed User
Longtime User
Informatix,
Great job, thank you for this lib, it increases the power of B4a.

What is the best way to scroll background by using LibGdx ? I checked the all examples but there is no such code about scrolling background.
 

Informatix

Expert
Licensed User
Longtime User
There's no background in libGDX as you may have in the B4A views. A background image is an image as any other image and to scroll it, you have to move it. For an endless scrolling, there are many possibilities. One of them is to use a repeated texture. Here's an example. I just added the xBkgd variable to the Perf_Skaters example and modified the drawing of the texture.
 

Attachments

  • scrolling.zip
    21.2 KB · Views: 314
Last edited:

strat

Active Member
Licensed User
Longtime User


Thank you informatix it's a good example. After first run, I quickly made some changes.
I've tried to change background.jpg first. 256X256 .jpg worked but scroll speed was not perfect. Speed was unstable, faster than the original. I've changed original background.jpg as transparent .png, but this time program didn't worked. It looks like there are some restrictions about image resolutions and formats.
 

Informatix

Expert
Licensed User
Longtime User
You probably removed the line "Config.useGL20 = True" or skipped it or your hardware does not support OpenGL 2 and in this case you have to set texBackground.EnforcePowerOfTwoImages to False.
You should really try to understand what I did because a picture with a different size will need different settings. For example, the width to draw will be texBackground.Width and not lGdx.Graphics.Width if the image is wider than the screen. And if your computation for NbOfRepetitionsX returns 0, then it cannot work.
 

strat

Active Member
Licensed User
Longtime User
I added texBackground.EnforcePowerOfTwoImages= False in my code. Now it works good. Only one restriction remained. An error like "Resolution must be power of 2" appear if background dimensions different than power of 2. I used a 1024x512 picture and it worked perfetcly. Thanks again.
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

This lib is amazing. I'm just getting my feet wet, but in just a few hours, I made some headway.

I took your Map_tIDE Example and played around with it, but I am getting some strange artifacts when it renders. My tiles are the same size as the tiles in your demo, but I'm getting strange lines between some of the tiles, and they aren't fixed, as I pan around, the lines come and go.

I have a feeling the problem is in this bit of code:

B4X:
    'Initializes the renderer
    Renderer.Initialize3(TiledMap, 1/32)
End Sub

Sub LG_Resize(Width As Int, Height As Int)
    'Sets the camera viewport
    Camera.Initialize
    Camera.SetToOrtho2(False, (Width / Height) * 32, 32)

I've put the full source here: https://drive.google.com/file/d/0B-zGIsrNkJF1cUZrTUpKY0FGSFE/edit?usp=sharing (figured I'd make a simple game to explore everything libGDX has to offer) I was shocked I could do what I did in just a few hours. It's far from finished.

BTW, if you compile and run the code, you'll see a gray bar on the right side of the map, because the map isn't filling the entire screen. The only way I can see to do that is change the numbers in this line.

B4X:
Camera.SetToOrtho2(False, (Width / Height) * 32, 32)

Again, you knocked the ball out of the park with this lib.

Congrats,

SterlingY
 

Informatix

Expert
Licensed User
Longtime User
I took your Map_tIDE Example and played around with it, but I am getting some strange artifacts when it renders.

Yes, I had the same visual glitches sometimes while playing with the maps. I think it's due to roundings and I have no workaround for now (I didn't really investigate). Maybe it's worth to search through the libGDX forum. We're probably not the first to notice that.

Two comments: libGDX has a media player (lgMusic) so the MediaPlayer lib is not necessary. And you should use the same unit scale for everything (currently you have a different unit scale for the tiles and for the car) because it's easier to position and size the objects when they share the same unit scale.
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix, Thanks for your response. I see where I've set the unit scale for the map, but I don't see where it's set for the car. Any thoughts on why there is a grey bar on the right side of the screen?
 

ananaiasa

New Member
Licensed User
Longtime User
Hi Informatix,
I've compiled the livewallpaper example via bridge to my nexus4.
It installs but when I add the wallpaper it force closes it also does the same thing with my GS3.
In the log:
LogCat connected to: B4A-Bridge: LGE Nexus 4
--------- beginning of /dev/log/main
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.
** Service (wallpaperservice) Destroy **
Ignoring event: lg_render. Raised from the wrong thread.
Ignoring event: lg_render. Raised from the wrong thread.
Streams_terminated
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=flm.b4a.lgdxlivewallpaper/.main }
no extras
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Streams_terminated
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Streams_terminated
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Streams_terminated
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=flm.b4a.lgdxlivewallpaper/.main }
no extras
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
running waiting messages (17)
** Activity (main) Resume **
** Service (service1) Destroy **
Ignoring event as service was destroyed.
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
** Activity (main) Pause, UserClosed = true **
Streams_terminated
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:flm.b4a.lgdxlivewallpaper
libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
** Activity (main) Create, isFirst = false **
running waiting messages (4)
** Activity (main) Resume **
** Service (service1) Destroy **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
** Activity (main) Pause, UserClosed = false **
Installing file.
PackageAdded: package:flm.b4a.lgdxlivewallpaper
Streams_terminated
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:flm.b4a.lgdxlivewallpaper

Just a bit confused...Any help would be appreciated
Cheers
 

Informatix

Expert
Licensed User
Longtime User
Are you sure that you compiled your program in Release mode?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…