I wrote a little subclass of Sprite to make it easier to draw my Sprites at the correct position using Box2D and LibGDX. You can find it on Bitbucket.

Just create a Box2DSprite and put it in the user data of a Body or Fixture and it will draw positioned, sized and rotated according to what you put it in.

Code example:

1 2 3 4 5

Bodybody = world.createBody(bodyDef);Fixturefixture = body.createFixture(fixtureDef);Box2DSpritebox2DSprite = newBox2DSprite(someSpriteOrTextureYouHave);body.setUserData(box2DSprite); // will draw on whole bodyfixture.setUserData(box2DSprite); // will only draw on the Fixture

To render, simply do:

1 2 3 4 5 6 7

batch.begin();// renders all the Box2DSprites in the given Box2D WorldBox2DSprite.draw(batch, world);// renders just this Box2DSprite, but you have to give in the Body or Fixture to render on (this way, it doesn't have to be in the user data)box2DSprite.draw(batch, body);box2DSprite.draw(batch, fixture);batch.end();

First off: I had to change your draw method in your FixtureSprite.java because world.getBodies(tmpBodies) wouldn't work (The method getBodies() in the type World is not applicable for the arguments (Array<Body>))

Sorry, the links were a bit outdated.This is now included in my mini library which grew a bit so it's in its own repository now. You can download a jar there and put it in your project like you're used to from other libraries.

Sorry, the links were a bit outdated.This is now included in my mini library which grew a bit so it's in its own repository now. You can download a jar there and put it in your project like you're used to from other libraries.

I have just one more question.

I will obviously be using this in my own projects, will I have to change the package declerations all the time or is there some sort of method to do this automatically, I mean at the top it has:

package net.dermetfan.libgdx.math;

Which is obviously different from my projects package, but even if I change it, when I go to reuse...well, repeats all over

Any ideas?

"This code works flawlessly first time and exactly how I wanted it"Said no programmer ever

- optional: if you'd like to be able to click the class names with ctrl + click to see the source: download this, click the arrow left to libgdx-utils.jar (which is now in the list), double click "Source attachement" and select libgdx-utils-sources.jar (which you also have to put into your project)

- click ok and ok again, done

Since you're starting out with LibGDX, I'm also using this post to shamelessly point you to my tutorials

I have no issue actually creating a game being honest, I can create side scrolling platformer games without any graphics....only problem I have is how to organize all the code, Java is new to me as well, I have an ok understanding of it but far from expert. Just struggle with some things, once I learn how to properly use classes my code will be more efficient I hope , by properly use I mean appropriate use :p

Watching the second episode atm, looking forward to the rest. You sound crazy nervous

"This code works flawlessly first time and exactly how I wanted it"Said no programmer ever

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org