[lib] libgdx-utils

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

[lib] libgdx-utils

Postby dermetfan » Fri Aug 09, 2013 3:26 am

I'd like to introduce a mini library I created mostly for myself but that found a few users over time.
It's pretty general purpose and makes various things easier.

A brief overview can be found on the homepage where you also find the download links, but I'll put it here too:

core

Graphics

Math
  • Noise - provides noise algorithms like diamond-square and midpoint-displacement
  • MathUtils - provides math utility methods
  • GeometryUtils - provides some methods for geometric calculations

Maps

Scene2D
  • FileChooser - a super class for various file chooser implementations
  • ListFileChooser - browse the file system and choose one more more files
  • TreeFileChooser - choose one or more files from a directory tree
  • CircularGroup - a WidgetGroup that aligns its children in a circle, allows advanced configuration
  • Popup - flexible popup system for things like tooltips, context menus and menu bars
  • JigsawPuzzle - a complete jigsaw puzzle mini game

Miscellaneous
  • AnnotationAssetManager - an AssetManager subclass loading assets from annotated fields
  • CutsceneManager - a cutscene interface and manager
  • Typewriter - "writes" a CharSequence like a typewriter with cursor using a CharSequenceInterpolator and an Appender
  • Appender - appends different CharSequences to a CharSequence based on time and duration
  • CharSequenceInterpolator - interpolates the length of a subSequence of a CharSequence by time and chars per second using the Interpolation class from libGDX
  • ArrayUtils - utility methods for arrays like boxing and selecting
  • Function - minimalistic rip-off of Java 8's Function
  • Pair - a generic key - value pair

Box2D extension

Graphics

Miscellanious
  • Box2DUtils - various operations and information on bodies, fixtures and shapes
  • Box2DMapObjectParser - creates Box2D scenes from a map (e.g. Tiled)
  • Breakable - easy way to create breakable bodies, fixtures and joints
  • Chain - manages, builds and modifies chain/rope simulations
  • MouseJointAdapter - create managed mouse joints in seconds
  • Autopilot - moves and rotates bodies to a destination
  • ContactMultiplexer - notifies multiple ContactListeners

This list might be outdated though.

Links

You can download from Maven Central.

I'm open for suggestions of any kind, hopefully it will be useful for someone.
Last edited by dermetfan on Sun Mar 01, 2015 3:57 pm, edited 14 times in total.
dermetfan
 
Posts: 408
Joined: Fri May 03, 2013 8:57 pm

Re: [lib] libgdx-utils

Postby xeoshow » Sat Aug 10, 2013 2:23 am

Very useful libgdx utils, and lightweight. Using it now, rating it 5 stars :D
xeoshow
 
Posts: 305
Joined: Mon Mar 18, 2013 1:12 am

Re: [lib] libgdx-utils

Postby just4phil » Sat Aug 10, 2013 6:54 am

Cool
Thx for sharing :-)
just4phil
 
Posts: 935
Joined: Fri Feb 03, 2012 10:07 pm
Location: Berlin

Re: [lib] libgdx-utils

Postby xeoshow » Sat Aug 10, 2013 9:15 am

Hi dermetfan,

As a heavy user, I saw you have a Car entity and used it in the Box2DTest.java, and also you have a Box2DMapObjectParser. is it possible to use your method to create such a Car in the tiled map and then load it via Box2DMapObjectParser? If yes, then various entities should can be created, which should can be quite useful...
xeoshow
 
Posts: 305
Joined: Mon Mar 18, 2013 1:12 am

Re: [lib] libgdx-utils

Postby dermetfan » Sun Aug 11, 2013 4:58 am

The Car class just creates a few bodies and joints in its constructor, that's all possible in the map editor with the Box2DMapObjectParser.
You just have to handle input manually of course. Using Box2DMapObjectParser#getBodies() you can get an ObjectMap<String, Body> containing all the parsed Bodies and the name of the MapObject they were parsed from. This way, you can put the needed bodies in your own entity class. There are also methods to get all the parsed Fixtures and Joints.
I might write a test for this some time.
dermetfan
 
Posts: 408
Joined: Fri May 03, 2013 8:57 pm

Re: [lib] libgdx-utils

Postby xeoshow » Mon Aug 12, 2013 4:01 am

Hi dermetfan,

I think for most users (developer), maybe below work flow seems will keep things simple:

1. Usually designer will design UIs, for example, design a background and some rock images, put them together on the screen.

2. Developer need to make the objects have the physcics attributes, take the rock above for an example, it is static, and have polygon shape...

So my question is: Can I put a rock image (not tiled) in the tiled map, and define the position for it? Then I use objects layer to draw exactly the same polygon bound for this rock? For the Car, similar way?
xeoshow
 
Posts: 305
Joined: Mon Mar 18, 2013 1:12 am

Re: [lib] libgdx-utils

Postby dermetfan » Mon Aug 12, 2013 5:17 pm

xeoshow wrote:Can I put a rock image (not tiled) in the tiled map, and define the position for it?

Your question is about the editor, right? Unfortunately that's not really possible in the Tiled editor. You'd need a tileset containing this image and place it on an image layer. You cannot resize or rotate it, though.
Gleed2D could do it for example, but there's currently no way to load its levels in libdgx (as far as I know). If they can be loaded into the map API, the Box2DMapObjectParser would be fine with it and you could edit your objects the way you described it.
dermetfan
 
Posts: 408
Joined: Fri May 03, 2013 8:57 pm

Re: [lib] libgdx-utils

Postby xeoshow » Thu Aug 15, 2013 1:37 pm

Hi dermetfan,

Seems found one problem related to FixtureSprite: I used below code and seems the image can not adapt to the physics size which defined via physics-body-editor-2.9.2:
Code: Select all
      // Create a loader for the file saved from the physics-body-editor.
      BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("levels/rock1.json"));

      // create rock
      BodyDef rockBodyDef = new BodyDef();
      rockBodyDef.type = BodyType.DynamicBody;
      rockBodyDef.position.set(...);  // set to your own position

      Body rockBody = world.createBody(rockBodyDef);

      FixtureDef rockFixtureDef = new FixtureDef();
      rockFixtureDef.density = 10000;

      // Create the body fixture automatically by using the loader.
      loader.attachFixture(rockBody, "rock1", rockFixtureDef, 1, 1, 1);
      FixtureSprite rock1FixtureSprite = new FixtureSprite(AssetsManager.getInstance().rock1Texture);
      rockBody.getFixtureList().get(0).setUserData(rock1FixtureSprite);


But if I change to the another rock, it seems fine, though the code is similar to above:
Code: Select all
      // Create a loader for the file saved from the physics-body-editor.
      BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("levels/level1.json"));

      // create rock
      BodyDef rockBodyDef = new BodyDef();
      rockBodyDef.type = BodyType.DynamicBody;
      rockBodyDef.position.set(createWorldVector(235, 30));

      Body rockBody = world.createBody(rockBodyDef);

      FixtureDef rockFixtureDef = new FixtureDef();
      rockFixtureDef.density = 10000;

      // Create the body fixture automatically by using the loader.
      loader.attachFixture(rockBody, "rock", rockFixtureDef, 1, 1, 1);
      FixtureSprite rock1FixtureSprite = new FixtureSprite(AssetsManager.getInstance().rockTexture);
      rockBody.getFixtureList().get(0).setUserData(rock1FixtureSprite);


I attached all the related files here:
levels.zip
(62.87 KiB) Downloaded 442 times

rock1.png is for AssetsManager.getInstance().rock1Texture
rock.png is for AssetsManager.getInstance().rockTexture

The snapshot for the wrong scenario:
snap.png
snap.png (9.36 KiB) Viewed 17218 times
xeoshow
 
Posts: 305
Joined: Mon Mar 18, 2013 1:12 am

Re: [lib] libgdx-utils

Postby dermetfan » Thu Aug 15, 2013 6:57 pm

I can't test it right now because I'm not home. Anyway from what I can read and see in the picture, I can say the following:
You're putting the FixtureSprite in the user data of a fixture, not the whole body. It sizes only to the size of the Fixture you put it in, not its body. As you can see in the picture, the rock is triangulated in different fixtures by the Body Editor. That's why it works for a rock with just one fixture and not for one with multiple ones.

I thought about renaming the FixtureSprite to Box2DSprite some time ago. I'd implement a method that lets you you choose if you want to draw on bodies or fixtures (or which one's user data the Box2DSprite is in). I guess I'm going to do this once I'm back home and installed some os on my computer again.
dermetfan
 
Posts: 408
Joined: Fri May 03, 2013 8:57 pm

Re: [lib] libgdx-utils

Postby xeoshow » Fri Aug 16, 2013 2:44 am

If I use
Code: Select all
rockBody.setUserData(rock1FixtureSprite);

insead of
Code: Select all
rockBody.getFixtureList().get(0).setUserData(rock1FixtureSprite);


Then there is no any rock image will be shown...
xeoshow
 
Posts: 305
Joined: Mon Mar 18, 2013 1:12 am

Next

Return to Libgdx Contributions

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest