0

Im trying to get a SpriteBatch drawn to sync up to the position of a body. Im not sure if this is the proper way to do this (in andengine you would just use physics connectors) But i tried drawing the sprite at the position the body was storing.

    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    camera.update();

    elapsedTime += Gdx.graphics.getDeltaTime();

    batch.setProjectionMatrix(camera.combined);

    batch.begin();

    batch.draw(walkAnimation.getKeyFrame(elapsedTime, true), 
    mrsaiBody.getPosition().x, mrsaiBody.getPosition().y, width/2, height/2);

    batch.end();
    mWorld.step(1/30f, 6, 2);
    mRenderer.render(mWorld, camera.combined);

The problem im having with this is, on the screen i see mrsaiBody's shape and i see the ground i made. When the shape makes contact with the ground the x and y values still continue to be affected by gravity even though the shape isnt. How can i get the current position of this shape to match up with position when i use batch.draw?

user3712476
  • 118
  • 1
  • 11
  • As far as I know the getPosition will get you the actual position of the body. Perhaps you stopped calling the debugRenderer at some point or you are tracking a different body than the one that collided. If that isnt the case, more code from your render function would help. – cavpollo Aug 06 '14 at 20:49
  • mmm it seems that i defined mrsaibody twice. I must have been tracking another instance of the body – user3712476 Aug 06 '14 at 20:56

0 Answers0