B4A Library libGDX - Game Engine

logo.png


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:
v1.14:
- I fixed a bug when Looping was changed during the execution of a sound;
- I added the RenderImageLayerAt function to all map renderers;
- I added the support of the new packaging tool used by B4A v10.70 (this mainly fixes the problem of / in paths of internal assets);
- I updated the manifest of all examples.

v1.13:
- I fixed a bug when the device was rotated (the Timer thread, for example, was not disposed which caused a problem in lgGestureDetector);
- I added two functions for Tiled maps: renderImageLayerAt and renderTileLayerAt.

v1.12:
- I added the .so libraries for 64 bits CPU;
- I added the PinchStop event to lgGestureDetector;
- I added the Orientation property to lgBox2DTransform;
- I fixed minor bugs.

v1.11:
- I fixed several bugs;
- I removed the unwanted delay after a change of screen in the Render event;
- I added the lgAsyncExecutor and lgAsyncTask classes;
- I added the missing file for the Progression demo;
- I updated the Freetype library (.so).

v1.10:
- I fixed several bugs;
- I added the support of expansion files: classes lgZipResourceFile and lgZipEntry, functions lgFiles.SetAPKExpansion and lgFiles.ExpansionFile (untested);
- I added a HashCode function to all lg...Array classes;
- I added a dozen of predefined colors to lgColor;
- I added the "raw_y" property to lgMapObjects;
- I added the grow, growX and growY functions to lgScn2DTableCell;
- I added the lerpAngle and lerpAngleDeg functions to lgMathUtils;
- I improved Atan2 in lgMathUtils;
- the collision objects of TMX tiles are now accessible via the Objects property of lgMapAnimatedTiledMapTile and lgMapStaticTiledMapTile;
- I added two new examples: Progression and Map_Box2D;
- I updated the manifest of most examples and templates.

v1.09:
- I fixed bugs, notably a major bug that crashed sometimes the game in the Render event handler when the current screen is changed;
- I added getColumnWidth and getRowHeight to lgScn2DTable and all classes that inherit from lgScn2DTable;
- I added the defaults function to lgScn2DTableCell;
- TMX files are loaded faster.

1.08:
- I fixed bugs;
- I added the lgFontGeneratorParameters class;
- I added CreateFontWithParam to lgFontGenerator;
- lgFontGenerator can add now a border and a shadow to the generated fonts (via CreateFontWithParam);
- I added Initialize2, LabelAlign and LineAlign to lgScn2DLabel;
- I added SetStateWithoutEvent to lgScn2DButton and lgScn2DTextButton;
- I added TitleLabel and TitleTable to lgScn2DWindow (this deprecates ButtonTable, Title, TitleWidth and TitleAlignment);
- I added getIndex to lgMapLayers and lgMapObjects;
- I added Target to actions of Scene2D;
- I removed Print from lgScn2DGroup (use Log(myGroup) instead);
- lgMapTiledMapImageLayer uses now float values for position;
- lgNinePatch uses now float values for paddings;
- lgPixmapPacker and lgPixmapPackerPage were rewritten (the many changes will break your existing code).

1.07:
- I fixed a few bugs, as usual;
- I added InitializeTransparentView to LibGDX;
- I added the lgKTXTextureData class to support the KTX and ZKTX file formats;
- I added a new demo: Format_KTX;
- I added argb8888 and argb8888ToColor to lgColor
- I added the lgMapAtlasTmxMapLoaderParameters class;
- I added Initialize3 and Load2 to lgMapAtlasTmxMapLoader;
- I added LoadExternal and IsInitialized to lgMapTmxMapLoader;
- I added FrameTiles to lgMapAnimatedTiledMapTile;
- I added a Tag property to lgSprite;
- I added hasOppositeDirection, hasSameDirection, isCollinear, isOnLine, isPerpendicular, AngleRad and rotateRad to lgMathVector2;
- I added rotateRad to lgMathMatrix4;
- I added clamp4, log, log2, Randomize, randomInt, randomInt2, randomSign, randomTriangular and randomTriangular2 to lgMathUtils;
- the random number generator of lgMathUtils uses now the xorshift128+ algorithm;
- I renamed Create2 to Combine in lgMesh;
- I removed the Create and Create3 functions from lgMesh;
- I removed the deprecated Color property from lgVertexAttributesUsage;
- it is possible now to change the KeyFrames array of lgAnimation after its initialization.

v1.06:
- I fixed a few bugs;
- I added a Texture property to lgSprite;
- I added the MotorJoint type to lgBox2DWorld;
- I added GetFixture to lgBox2DBody;
- I added Initialize3 to lgShapeRenderer to allow the use of custom shader programs;
- I added ScaleEffect to lgParticleEffect;
- I added CleanUpBlendFunction to lgParticleEmitter;
- I added scl2 to lgMathVector2;
- I added IsEnabled to lgGLProfiler;
- I added Percent, VisualPercent and VisualInterpolation to lgScn2DProgressBar;
- I added Percent, VisualPercent, VisualInterpolation and VisualInterpolationInverse to lgScn2DSlider;
- I added isLeftEdge, isRightEdge, isTopEdge, isBottomEdge to lgScn2DScrollPane;
- The Reset function of lgScn2DTableCell sets now all constraints to their default values;
- I modified the Map_Hexagonal example to display the coordinates of the touched hex.

v1.05:
- I fixed two bugs;
- the latest TMX format of Tiled Map Editor is now properly decoded (with support of animated tiles and image layers);
- I added the RenderImageLayer function to the map renderers;
- I added the lgMapTiledMapImageLayer class for the image layer of tiled maps;
- I added the OffsetX and OffsetY properties to lgMapAnimatedTiledMapTile and lgMapStaticTiledMapTile;
- I added the CurrentFrame and CurrentFrameIndex properties to lgMapAnimatedTiledMapTile;
- I added the FinishLoadingAsset function to lgAssetManager;
- I added the SetAlpha function to lgBitmapFontCache;
- I added FixtureCount and GetAllFixtures to lgBox2DWorld;
- I added the ResetOnTouchUp property to lgTouchpad;
- I removed Scale and Div from lgMathVector3 because these functions were deprecated.

v1.04:
- I fixed various bugs, notably a bug affecting the Backspace key on the virtual keyboard of some devices;
- I added the missing OpenGL functions in lgGL;
- I added the KeepWithinStage function to lgDragAndDrop;
- I added the dampingRatio and frequencyHz fields to lgBox2DWeldJointDef;
- I added the DampingRatio and Frequency properties to lgBox2DWeldJoint;
- I added the Line6 function to lgShapeRenderer;
- I added VisualScrollPercentX, VisualScrollPercentY and FlickScrollTapSquareSize to lgScn2DScrollPane;
- the LineHeight property of BitmapFonts can be modified;
- I updated the .so files;
- I added an example: Sensors.

v1.03:
- I fixed various bugs;
- I added the VertexColor property to lgPolygonSprite;
- I added the Equals function to lgArray;
- I renamed Ellipse to Ellipsis in lgScn2DLabel;
- I improved the code of lgPixmapIO (less memory used, PNG with compression);
- I fixed a problem with the fragment shaders of two examples.

v1.02:
- I fixed 3 bugs in lgScn2dTable and a few others in other classes;
- I added 4 examples using shaders;
- I removed the lgDefaultGroupStrategy class because it was useless and changed the initialization of lgDecal objects;
- I added the SetRotation function to lgDecal;
- I added the Tint function to lgBitmapFontCache;
- I added the Cancel and Reset functions to lgGestureDetector;
- I added the IsKeyJustPressed function to lgInput;
- I added the Colinear and EnsureCCW functions to lgMathGeometryUtils;
- I added the Equals function to lgMathGridPoint2, lgMathGridPoint3 and lgMathRay;
- I added the IntersectRayRay and DistanceLinePoint2 functions to lgMathIntersector;
- I added the Extract4x3Matrix function to lgMathMatrix4;
- I added the WindowSize property to lgMathWindowedMean;
- I added the IsDrawing function to lgShapeRenderer;
- I added the ColorUnpacked field to lgVertexAttributesUsage;
- I added the Clear function to lgScn2DButtonGroup;
- I added the CancelTouchFocus property to lgScn2DDragAndDrop;
- I added the Rows, Columns, BackgroundTop, BackgroundLeft, BackgroundBottom, and BackgroundRight properties to lgScn2DTable;
- I added the ClearActor function to lgScn2dTableCell;
- I added the ActionsRequestRendering property to lgScn2DStage;
- I renamed CancelTouchFocus2 to CancelTouchFocusExcept in lgScn2DStage;
- I removed the Clear function from lgScn2dTableCell;
- The color markups are now supported by lgScn2dLabel and lgScn2dWindow (title).

v1.01:
- I fixed a handful of minor bugs and a big bug affecting the screen events;
- I added IsDrawing in lgSpriteBatch.

v1.0:
- I fixed bugs in various classes;
- I rewrote big chunks of internal graphics classes;
- the TMX map loaders are now able to read the Rotation property;
- the FrameDuration property of lgAnimation can now be changed during the animation;
- I added an Initialize function to lgMapAnimatedTiledMapTile to be able to set dynamically an animated tile;
- I added two new classes for debugging: lgGLProfiler and lgScn2DDebugRenderer;
- I added DebuggingEnabled and DebugColor to all actors of Scene2D;
- I added ChildrenDebuggingEnabled to all groups of Scene2D;
- I added CellDebugColor to lgScn2DTable and removed all its debug functions;
- I added SetCenterPosition, CenterX and CenterY to all actors of Scene2D;
- I replaced the Widget word by Actor in lgScn2DTableCell;
- I added the Equals and HashCode functions to a few lgMath classes;
- I added the ApproxLength function to lgMathBezier, lgMathBSpline and lgMathCatmullRomSpline;
- I added Set3, SetPosition2, Contains2, Circumference and Area to lgMathCircle;
- I added Set3, SetPosition2, Circumference and Area to lgMathEllipse;
- I added Merge2, Area and Perimeter to lgMathRectangle;
- I added Len and Len2 to lgMathSegment;
- I added Volume and SurfaceArea to lgMathSphere;
- I added Interpolate to lgMathVector2 and lgMathVector3;
- I added the following functions to lgMathMatrix4: mulLeft, Set2, Set3, Set4, Set5, Set6, ScaleX, ScaleY, ScaleZ, ScaleXSquared, ScaleYSquared, ScaleZSquared;
- I added a LoadMipMap event and replaced UseHardwareMipMap by Get/SetGenerationMethod in lgMipMapGenerator;
- Box2D has now its own .so library;
- I added Separations to lgBox2DWorldManifold;
- I added the following functions to lgBox2DEdgeShape: Vertex0, SetVertex0, SetVertex0_xy, HasVertex0, Vertex3, SetVertex3, SetVertex3_xy, HasVertex3;
- I added LocalAxisA to lgBox2DPrismaticJoint;
- I added two new classes to Box2D: lgBox2DMotorJoint and lgBox2DMotorJointDef;
- I added the LoadTextureWithParam function to lgAssetManager and the related lgTextureLoaderParam class;
- I added two new properties (Normalized, Type) and a function (HashCode) to lgVertexAttribute;
- I renamed Color to ColorPacked in lgVertexAttribute;
- I renamed Loop to Repeat in lgSound;
- I renamed consumeCompressedData to consumeCustomData in all TextureData classes;
- I protected some important classes against a repeated initialization to avoid memory leaks and side effects;
- I added a Scene2D_EventsHierarchy demo and modified the following examples: BitmapFont, FrameBuffer, Map_tIDE and Scene2D_Table.

v0.99:
- I fixed numerous bugs, especially in Scene2D where the listeners did not work as expected and actors were not fully re-initialized when Initialize was called again;
- I set to Null the internal objects of classes after a call to Dispose;
- I added the following functions:
+ IsInitialized where it was still missing;​
+ Move to lgArray;​
+ ComputeScaleForPixelHeight to lgBitmapFont;​
+ SetNameForColor, GetColorByName and SetAlpha to lgColor;​
+ Clear to lgMapLayers;​
+ Lerp to lgMathUtils;​
+ Load3 and LoadEmitterImages3 to lgParticleEffect;​
+ SetString to lgScn2DLabel;​
+ Initialize4 to lgScn2DSpriteDrawable, lgScn2DTextureRegionDrawable and lgScn2DTiledDrawable;​
+ UpdateMatrices to lgShapeRenderer;​
+ SetCenterX, SetCenterY and SetCenter to lgSprite;​
- I added a ChildrenCount property to lgScn2DGroup;
- I added a Draw event to lgScn2DImage and lgScn2DLabel;
- I added a Disabled property to lgScn2DScrollPane;
- I added the following predefined colors to lgColor: Olive, Purple, Maroon, Teal, Navy;
- I renamed the alpha function to to255 in lgColor;
- lgBitmapFont and lgBitmapFontCache now support in-string colored text through a simple markup language (see the demo);
- I added the MarkupEnabled property to lgBitmapFont;
- I added a BitmapFont demo;
- I modified the FrameBuffer demo;
- I removed the yUp and yDown parameters from the tiled map loaders and renderers (yUp is now always true);
- I removed Rotation and rotateBy from lgScn2DLabel, lgScn2DList, lgScn2DSelectBox and lgScn2DTouchpad because they were not effective.

v0.98:
- I fixed a bug affecting the scaling and rotation of lgScn2DImage;
- I fixed a bug in lgBox2DParticleEmitter;
- I fixed a bug in lgScn2DButton;
- I added the lgFrameBuffer class and a FrameBuffer demo;
- I added the IsInitialized function where it was missing;
- I added the PolygonRegion type to lgAssetManager;
- I added a Payload parameter to the SrcDragStop event of lgScn2DDragAndDrop;
- I added the Draw2 function to lgScn2DSpriteDrawable;
- I added the Set3 function to lgMathMatrix3.

v0.97:
- I fixed a few bugs (the immersive mode works now as expected);
- I found a solution for the repetition of tiles, so I added two properties (RepeatX, RepeatY) to lgMapTiledMapLayer and I modified the Map demos.
- I added an IsInitialized function to 15 classes;
- I added a RemoveRange function to all the lgArray classes;
- I added the Fling function to lgScn2DScrollPane;
- I added the IsVisualPressed function and the VisualPressedDuration property to lgScn2DClickListener.

v0.96: Major update!
In this version, I:
- removed all the code supporting OpenGL ES 1.x
- fixed a few bugs
- added new classes for decals (2D objects in 3D space): lgDecal, lgDecalBatch, lgCameraGroupStrategy, lgDefaultGroupStrategy, lgSimpleOrthoGroupStrategy
- added an example for decals
- removed the Mesh example as it cannot work with OpenGL 2 without being rewritten
- added the lgScn2DProgressBar class and modified the Scene2D_TextFieldsAndSliders example to show how to use it
- added the IsInitialized function to a dozen of classes
- added these functions:
lgBox2DWheelJoint: isMotorEnabled
lgFontGenerator: CreateFont5, CreateFont6 (for mip maps and filters)
lgMathGeometryUtils: polygonArea, triangleArea
lgMathMatrix3: getScale, getTranslation, setToRotation2, setToRotation3, setToRotationRad, rotateRad
lgMathMatrix4: det3x3, setToRotationRad, setTranslation
lgMathUtils: isEqual, isEqual2, isZero, isZero2
lgMesh: CalculateRadius, CalculateRadius2, CalculateRadiusSquared
lgScn2DDragAndDrop: SetTouchOffset
lgSprite: SetOriginCenter
- added these properties:
lgBox2DJoint: CollideConnected
lgBox2DDistanceJoint, lgBox2DFrictionJoint, lgBox2DRopeJoint, lgBox2DWeldJoint: LocalAnchorA, LocalAnchorB
lgBox2DGearJoint: Joint1, Joint2
lgBox2DPrismaticJoint: LocalAnchorA, LocalAnchorB, MaxMotorForce, ReferenceAngle
lgBox2DWheelJoint: LocalAnchorA, LocalAnchorB, LocalAxisA
lgMathMatrix3: Rotation, RotationRad
lgScn2DActor: isTouchable
lgScn2DScrollPane: ScrollHeight, ScrollWidth, VariableSizeKnobs
lgScn2DWindow: ButtonTable, Resizable, ResizeBorder, TitleWidth
- renamed the functions Translate -> MoveBy, Rotate -> RotateBy and Size -> SizeBy of the lgScn2DActor class
- removed toScreenCoordinates from lgStage and toWindowCoordinates from lgScissorStack
- removed the yDown parameter from ComputePolygon and ComputePolygon2 in the lgMathConvexHull class
- improved a bit the help text of a few functions

v0.95:
Bugfixes and minor improvements
New classes: lgFloatArray, lgIntArray, lgShortArray
The lgMathConvexHull and lgMathEarClippingTriangulator classes are now usable
New functions:
- lgPerspectiveCamera: GetPickRay
- lgScn2DStage: SetViewport2
- lgMathFrustum: pointInFrustum2, sphereInFrustum2, sphereInFrustumWithoutNearFar2
- lgBox2DChainShape: createLoop2
- lgMathIntersector: intersectSegments2
- lgMathVector2: isUnit, isUnit2, isZero, isZero2
- lgMathVector3: set2, isUnit2, isZero2
New configuration setting: useImmersiveMode (for Kitkat)

v0.94:
Bugfixes (including a serious bug with the listeners of Scene2D)
New classes: lgMapTmxMapLoaderParameters and lgMipMapGenerator
New functions:
- lgAnimation: KeyFrames
- lgAssetManager: LoadTMXWithParam
- lgBitmapFontCache: SetColors, SetColors2, SetColorsRGBA
- lgGestureDetector: Initialize2
- lgMapTmxMapLoader: Initialize3, Load2
- lgMathVector2: Rotate90
- lgMesh: UpdateVertices, UpdateVertices2
- lgMusic: Duration, Position
- lgScn2DClickListener: inTapSquare2
- lgScn2DList: ItemHeight
- lgShapeRenderer: RectLine
- lgSocket: RemoteAddress
- lgSprite: Alpha, SetFlip
New parameters: ListBox and ScrollPane styles in lgScn2DSelectBoxStyle.Initialize
New example: Filters
Modified example: Map_tIDE (I fixed the visual issues)
New configuration setting: disableAudio

v0.93:
Bugfixes (including the problem reported for the Get...List functions of Box2D)
Class rewritten: lgTexture (some functions have been added, some have been removed)
New configuration setting: useGLSurfaceViewAPI18 (for Gingerbread and older versions)
New functions: lgFileHandle.equals, lgFileHandle.hashCode, lgShapeRenderer.Triangle2
New class: lgPerspectiveCamera (for 3D)
New example: ShapeRenderer
Modified example: Perf_Skaters (the background scrolls endlessly now)

0.92:
Minor bugfixes
Internal changes for texture handling
Viewport parameters added to CalculateScissors in lgScissorStack
New function in lgScn2DScrollPane: setScrollBarPositions
New function in lgMathVector2: epsilonEquals2
New function in lgMathIntersector: intersectRectangles
Initialize3 and FindDirectionForIsoView functions removed from lgOrthographicCamera

0.91:
Bugfixes (including the problem reported for tIDE properties)
New event for gesture detector: PanStop
New Initialize function for Bitmapfont to allow to flip the font
New Rect functions for the ShapeRenderer
New class: lgMapIsometricStaggeredMapRenderer (for staggered isometric maps)
New function for lgScn2dScrollPane: Cancel
lgMathBezier and lgMathBresenham2 are now fully usable
New functions in lgMathIntersector
A few internal changes to improve performance and stability

0.9:
Bugfixes
New class: lgArray (ordered array with an initial capacity)
Many Lists have been replaced by lgArray for a better performance and more possibilities
Improved documentation (mainly in lgMath and lgSprite classes)
lgMathBSpline and lgMathCatmullRomSpline are now fully usable
New example: SplinePath
New function for particle effects and particle emitters: BoundingBox
New property for lgScn2DLabel: Ellipse

0.8:
First release
 
Last edited by a moderator:

stevel05

Expert
Licensed User
Longtime 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.
 

Pendrush

Well-Known Member
Licensed User
Longtime User
First of all, thank you for your time and effort to wrap this great lib.
Is this a bug?

B4X:
Dim tIDELoader As lgMaptIDEMapLoader
TiledMap = tIDELoader.Initialize2("maps/tide/Map01.tide")
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
            TiledMap.Layers.Remove(i)
        End If
    Next

line
B4X:
Log (TiledMap.Layers.Get(i).Name)

don't return any value.
lib version 0.9
 

walterf25

Expert
Licensed User
Longtime User
How i can use Gestures library with libGDX?
My app rush in RENDER sub.

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

Hope this helps!

B4X:
Dim gestures As lgGestureDetector
gestures.Initialize("gestures")

You get the following subs with it!

B4X:
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 lgMathVector2) As 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
 

Informatix

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

B4X:
Dim tIDELoader As lgMaptIDEMapLoader
TiledMap = tIDELoader.Initialize2("maps/tide/Map01.tide")
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
            TiledMap.Layers.Remove(i)
        End If
    Next

line
B4X:
Log (TiledMap.Layers.Get(i).Name)

don't return any value.
lib version 0.9

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.
 

DoogieDog

Member
Licensed User
Longtime 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: { }
 

Informatix

Expert
Licensed User
Longtime 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).
 

Puck

Member
Licensed User
Longtime 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.
 

Informatix

Expert
Licensed User
Longtime User
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?

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.
 

Puck

Member
Licensed User
Longtime 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 :)
 

walterf25

Expert
Licensed User
Longtime 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.

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
 

Puck

Member
Licensed User
Longtime 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

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.
 

walterf25

Expert
Licensed User
Longtime 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.

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

Informatix

Expert
Licensed User
Longtime 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.

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

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.

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

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.

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

The coordinates of the image use a different mapping system than the BOX2d meters system as in your jbox2d examples.

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.

I had trouble translating that code over to libGDX since some of the commands are a bit different.

Post the code and I'll explain.

Some said to use body.userdata to save the sprite objects but I had issues with that even.

What issues?

You are a legend here

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

Laurent95

Active Member
Licensed User
Longtime 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 :) )
 
Top