LibGDX Box2D incorrect sprite position of moving body -


I am trying to create a 2D car scrolling game. I am using wheel joints to move the car.

Here is the screenshot when the car does not run.

And when the car moves you can see that the sprites are not in the right position.

Here the car is the constructor of the object. body

and code to attract relevant sprites for bodies on the screen. (Body body: body) for if (body.getUserData ())

= null & amp; Body.getUserData () Examples of Sprite) {Sprite Phantom = (Phantom) body.getUserData (); Sprite.setPosition (body.getPosition () .x - sprite.getWidth () / 2, body.getPosition (). Y - sprite.getHeight () / 2); Sprite.setRotation (body.getAngle (* * MathUtils.radiansToDegrees); Sprite.draw (batch); }

Sorry, if my question can not be very specific or clear I am new to Stackoverflow.

Edit [Hull]

Just put in the render method [right]

  Renderer.render (world, Camera.combined);  

After gl.clear I was doing this after drawing everything on the screen. [Mist]

It seems that you do your physical updates after submitting it, because your The physically-debunked polygon appears more than the previously gone phantom, you can first try to update your physics and then attract your phantom.

There should not be anything wrong with the code / calculation.

If you are already doing this probably because your physical simulation updates are updated more often than your rendering-loop.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -