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:

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I've been studying some Java code, but I'm still perplexed. Maybe you can decipher it.

I don't need to render the object as this code does. It's the casting that always throws me off. The code is something like this:

B4X:
Private ShapeRenderer sr;
.
.
.

sr.setProjectionMatrix(camera.combined);
for (mapObject object:  map.getLayers().get("objects").getObjects)){

Polyline line = ((PolylineMapObject) Object).getPolyline();

sr.begin(ShapeType.line);
sr.polyline(line.getTransformedVertices());
sr.end();
}
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I should also mention that I get random null pointer exceptions, and they don't seem to be tied to anything in particular. Once I get the polyline issue resolved, I'll send the project to you. Maybe you can figure it out. The app will just crash, even when it isn't being manipulated.

-S
 

Informatix

Expert
Licensed User
Longtime User
Informatix,

I've been studying some Java code, but I'm still perplexed. Maybe you can decipher it.

I don't need to render the object as this code does. It's the casting that always throws me off. The code is something like this:

B4X:
Private ShapeRenderer sr;
.
.
.

sr.setProjectionMatrix(camera.combined);
for (mapObject object:  map.getLayers().get("objects").getObjects)){

Polyline line = ((PolylineMapObject) Object).getPolyline();

sr.begin(ShapeType.line);
sr.polyline(line.getTransformedVertices());
sr.end();
}

Here's an example to get the first object (a polyline) in the object layer named "myobjects":
B4X:
Dim ObjectLayer As lgMapLayer
ObjectLayer = Maps.Layers.Get2("myobjects")
Dim myPolyObj As lgMapPolylineMapObject = ObjectLayer.Objects.Get(0)
Dim myPoly As lgMathPolyline = myPolyObj.Polyline
 

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I can read the Vertices and draw the Polyline as a ChainShape, but of course, the the Vertices are in an unscaled coordinate system. Any thoughts on applying a scale to all vertices?

I doubt I need to explain this, but when the TiledMap is rendered, I can supply a UnitScale, however, I can't figure out how to do the same with the Polyline, nor can I scale the ChainShape. The Polyline has both setScale and Scale methods, but they don't seem to do anything.

-SterlingY
 
Last edited:

sterlingy

Active Member
Licensed User
Longtime User
I'm trying to get a list of joints associated with a Box2D body, but for some reason, when I check the size, it always returns Zero, which destroys my If Then loop

The code is something like this:

B4X:
    Dim heroBody As lgBox2DBody
    Dim currentJoints As lgArray
    currentJoints.Initialize
   
    heroBody = globals.numbersHeld.Get(0)
    heroBody.GetJointList(currentJoints)

currentJoints.size is always ZERO despite the fact that joints exist and are functioning as intended. I can manipulate heroBody in every other factor I have tried.

-S
 

Informatix

Expert
Licensed User
Longtime User
Informatix,

I can read the Vertices and draw the Polyline as a ChainShape, but of course, the the Vertices are in an unscaled coordinate system. Any thoughts on applying a scale to all vertices?

I doubt I need to explain this, but when the TiledMap is rendered, I can supply a UnitScale, however, I can't figure out how to do the same with the Polyline, nor can I scale the ChainShape. The Polyline has both setScale and Scale methods, but they don't seem to do anything.

-SterlingY
I never used a polyline so I have no idea on the subject, except that I see in the code that you have to call getTransformedVertices if you changed the scale of your polyline.
 

Informatix

Expert
Licensed User
Longtime User
I'm trying to get a list of joints associated with a Box2D body, but for some reason, when I check the size, it always returns Zero, which destroys my If Then loop

The code is something like this:

B4X:
    Dim heroBody As lgBox2DBody
    Dim currentJoints As lgArray
    currentJoints.Initialize
 
    heroBody = globals.numbersHeld.Get(0)
    heroBody.GetJointList(currentJoints)

currentJoints.size is always ZERO despite the fact that joints exist and are functioning as intended. I can manipulate heroBody in every other factor I have tried.

-S
Same problem for GetFixtureList. I'm going to fix that. Thanks for the report.
 

sterlingy

Active Member
Licensed User
Longtime User
I never used a polyline so I have no idea on the subject, except that I see in the code that you have to call getTransformedVertices if you changed the scale of your polyline.

Funny how I completely miss something. This problem is solved. Thanks. In regards to the getJointsList, I'm on hold until there is a solution. I can work on other aspects of the app, however.

-SterlingY
 

sorex

Expert
Licensed User
Longtime User
@Informatix

I know you probably hate questions like this but...

I there a way to seperate things so that we don't need all the 3D, physics and other moders stuff
when we just want to create an 80 style retro games

I mean, 2Mb to move a sprite around the screen is slightly overkill :)
 

Informatix

Expert
Licensed User
Longtime User
@Informatix

I know you probably hate questions like this but...

I there a way to seperate things so that we don't need all the 3D, physics and other moders stuff
when we just want to create an 80 style retro games

I mean, 2Mb to move a sprite around the screen is slightly overkill :)
That's why I created the Lite version, but I agree that this version is still a big fat baby. I could reduce a lot more the JAR size but I don't want to maintain too much different versions of the library. And the choice is difficult to do among the things to remove (probably the network and the math stuff, maybe the stage classes...).
 

sterlingy

Active Member
Licensed User
Longtime User
New version! YAY!!

I'll be working with it over the next few days, but as I'll be travelling I'm not sure how much time I can give it. With the Joint List problem solved, however, I think I'll have a fully functioning app, minus graphics and level design. Fingers crossed.

-SterlingY
 
  • Like
Reactions: JEG

walterf25

Expert
Licensed User
Longtime User
Hi Frederick, thanks for the new version of libgdx, i recently started working on my next app after finishing up everything else i had going on, i must say i'm very excited to finally have time to dig into libgdx completely.
My app is based on the whack a mole game, so far i have the background set up and can make the moles pop up and detect the hits then they pop back down into their holes.
I wanted to switch the image of the mole when it gets hit to an image of a bleeding mole, but i came across a strange behavior on the textures when i try to implement that.
for example right now i have an image of justin beiber and when you tap him on the head i switch to another image of him but one where he is bruised and bleeding, the strange behavior is when i hide him back down, it switches to another different image, then the next time it switches to a completely different image, i'm not sure what's going on, i'm probably going crazy but i've already gone at least 20 times through my code and can't find where the mistake is.

this is the code where i set up the image on the texture in the LG_Create sub
B4X:
    For i = 0 To 8
    moletexture(i).Initialize("assets/beiber.png")
    moletextureregion(i).InitializeWithTexture2(moletexture(i), 128, 128)
    Next

this is where the actor is initialized
B4X:
    moleactor(0).Initialize("moleactor1")
    moleactor(0).setSize(18%x, 28.33%y)
    moleactor(0).setPosition(lGdx.Graphics.Width/2 - 8.165%x, 642 - (128 + 660))
    moleactor(0).ZIndex = 1

and when the actor is hit i switch the image to a different image here in the Molelistener_Click Event
B4X:
Sub molelistener_Click(Event As lgScn2DInputEvent, X As Float, Y As Float)
moletexture(0).Initialize("assets/bleeding.png")
moletextureregion(0).InitializeWithTexture2(moletexture(0), 256, 256)
actorhit = True
End Sub

i'm including the apk file so you can see the issue i'm having, hopefully you'll be able to figure out what's going on.
https://dl.dropboxusercontent.com/u/82367588/Whack A Beiber.apk

Thanks for your hard work Frederick

Walter
 

Informatix

Expert
Licensed User
Longtime User
for example right now i have an image of justin beiber

It seems that you have a little sister.... :)

Your snippets of code reveal two problems: one is with memory (you create eight times the same texture and do not dispose it when you re-initialize the instance) and another with programming: why do you load many times the same texture? You should load two textures, one with Beiber and his angel face, and one with a bruised face. Convert this texture to a drawable (Texture -> TextureRegion -> lgScn2DTextureRegionDrawable or Texture -> Sprite -> lgScn2DSpriteDrawable). Then create eight actors (lgScn2DImage class) that use one of these drawables depending on the context (cf. the drawable property).

And if the problem is still there after a proper rewriting, you should place a Log() everywhere to know what functions are called, what values are set, what parameters are passed, etc. (since you cannot use reliably the B4A debugger).

Hope that helps.

Note: I receive all forum messages in my mailbox so it is useless to send a private message to notify me. If I don't answer, there's a reason (I was too busy the past days and not always behind my computer).
 
Last edited:

sterlingy

Active Member
Licensed User
Longtime User
Informatix,

I've had time to work with v.93

So Get..List functions are working, but I'm not making much headway with doing anything with it. I'll explain what I'm trying to do: Imagine trying to create a train where each car is a BODY, and the connection between them is a JOINT, but periodically, I want to insert a new car between the first and second car. My thought was to get the JOINT from car1, and change it's BodyB to the car being inserted, then create a new JOINT to attach the inserted car to what is now the third car.

The problem is that I can get the list of associated joints, but I can only read, not write to the BodyA and BodyB properties.

As a temporary fix, I destroy the list of world's joints and then reconstruct the order of the bodies and associated joints. This is however sloppy and ultimately will not work for me, and it's a bit buggy.

On another topic, I looked at your Skater example, hoping the repeating background would have solved the repeating or swapping tiled maps, but I see it's a different beast. Any update on when you might be able to work on that?

About flipped sprites. Is it proper behavior that Sprite.Flip(x,y) flips every time you call it? For example every time you code Sprite.Flip(false, true) it performs a flip operation, as opposed to keeping it flipped from it's original state.

I started to clean up my code and make it better organized so I can scale it more efficiently, and I created a new Activity to handle loading of assets, the main menu and options, then make the gameplay a separate Activity. It occurred to me that this might be the wrong approach with libGDX. What are your thoughts?

Lastly, you may remember a problem we discussed a few months ago, where there were some anomalies when moving around a tiled map. I thought the problem was solved when the tileset didn't have a pixel gap between each tile. Seems like I'm wrong. I think you knew what caused it. Any hopes in it being resolved?

Cheers,

SterlingY

P.S. I haven't played with the Perspective Camera yet, but I think I need to get everything else through my head first.
 

sterlingy

Active Member
Licensed User
Longtime User
Some info on the inserting Bodies and Joints into a chain:

I rewrite my code, after I learned that it is not possible to change a Joint's BODY associations, once it has been created.

B4X:
Public Sub Initialize(vBodyA As lgBox2DBody, vBodyB As lgBox2DBody)


    Dim heroBody As lgBox2DBody
    Dim connectionsList As lgArray
    connectionsList.Initialize
   
    heroBody = globals.numbersHeld.Get(0)
    heroBody.GetJointList(connectionsList)
   
    If globals.numbersHeld.Size = 1 Then
        globals.numbersHeld.Add(vBodyB)
    Else
        globals.numbersHeld.InsertAt(1, vBodyB)
    End If

    Log("numHeld:" & globals.numbersHeld.Size)
    Log("cJ: " & globals.connectionsList.Size)

    'Dim HeroJoint As lgBox2DRevoluteJoint
    If connectionsList.Size > 0 Then
    '    HeroJoint = connectionsList.Get(0)
        GamePlay.World.DestroyJoint(connectionsList.Get(0))
    End If

    Dim connectorJointDef As lgBox2DRevoluteJointDef
       
    If globals.numbersHeld.size = 2 Then
        connectorJointDef.bodyA = globals.numbersHeld.Get(0)   
        connectorJointDef.bodyB = globals.numbersHeld.Get(1)
       
        connectorJointDef.localAnchorA.Set(-5 , 0)
        connectorJointDef.localAnchorB.Set(2 , 0)
        connectorJointDef.collideConnected = False
       
        GamePlay.World.CreateJoint(connectorJointDef)
    Else
        connectorJointDef.bodyA = globals.numbersHeld.Get(1)   
        connectorJointDef.bodyB = globals.numbersHeld.Get(2)
       
        connectorJointDef.localAnchorA.Set(-2 , 0)
        connectorJointDef.localAnchorB.Set(2 , 0)
        connectorJointDef.collideConnected = False
       
        GamePlay.World.CreateJoint(connectorJointDef)
    End If

End Sub

I'm getting a class mismatch error on the following line: "
GamePlay.World.DestroyJoint(connectionsList.Get(0))"

It says that you can't cast a JointEdge to a Joint.

DestroyJoint wants an lgBox2DJoint, and my joints are RevoluteJoints.

-SterlingY
 

Informatix

Expert
Licensed User
Longtime User
Hello,

I cannot fully help you before tomorrow evening because I have a lot of important things to do but here are quick answers to some of your questions: the pixel gap is due to roundings and the only solution that I know is to use the screen resolution for your tile renderer (no unit scale set); I didn't forget your demand for an endless scroll; Flip() flips the sprite every time; World.GetAllJoints returns a list of Joints but Body.GetJointList returns a list of JointEdges so, to remove the joint, you have to use myJointEdge.Joint.
 

sterlingy

Active Member
Licensed User
Longtime User
Thanks for checking in. I'll see what I can do in the meantime.

-SterlingY
 

walterf25

Expert
Licensed User
Longtime User
It seems that you have a little sister.... :)

Your snippets of code reveal two problems: one is with memory (you create eight times the same texture and do not dispose it when you re-initialize the instance) and another with programming: why do you load many times the same texture? You should load two textures, one with Beiber and his angel face, and one with a bruised face. Convert this texture to a drawable (Texture -> TextureRegion -> lgScn2DTextureRegionDrawable or Texture -> Sprite -> lgScn2DSpriteDrawable). Then create eight actors (lgScn2DImage class) that use one of these drawables depending on the context (cf. the drawable property).

And if the problem is still there after a proper rewriting, you should place a Log() everywhere to know what functions are called, what values are set, what parameters are passed, etc. (since you cannot use reliably the B4A debugger).

Hope that helps.

Note: I receive all forum messages in my mailbox so it is useless to send a private message to notify me. If I don't answer, there's a reason (I was too busy the past days and not always behind my computer).
Hi Frederick, thanks for the reply, in talking to Sterlingy about this same issue, he also suggested a couple of things, i've also implemented your suggestions of converting the texture to a drawable, and i'm not creating the same texture eight times as i was doing previous, i created a different class which takes care of creating the actors, however i did struggle a bit in placing the background actors and the main actors in the right zindex order, another issue i was having was when adding a clicklistener to the actors, for some reason only the last added actor was actually firing the change image code inside of it, it is now working, i had to change the click listener code to the main activity, i defined the click listener from the main activity and just passed it as a parameter to the creator actor sub in the createactors class, this is now working as i wanted. Thanks alot for your reply again Frederick, i understand that you only port this libraries but still i'am aware that this requires a lot of work and for that i'm greatful as this provides us with an opportunity to create better apps.

On another note, i've been trying to do some research about creating a camera shaking effect, for example when there's an explosion i've seen some really nice apps where the whole screen does this shaking effect, i noticed you posted the simplex noise library and that this is based on the perlin algorithm, i'm not sure if you have any input or experience on this, but would you know if the simplex noise library would be able to be used for something like that?

Thanks,
Walter
 
Top