# Getting body position

I am using BodyA.getPosition().x and BodyA.getPosition().y to get the x and y vector of a body location so i may attach some text above its head, but the log of that position prints out something like 3.666757..... I want this text to be moving when the body moves so it should be relative to the body position at all times until removed. Currently when I try to use this

speech = new TickerText( 0, 0, font,
ptext, new TickerText.TickerTextOptions( 10 ),
ResourceManager.getInstance().vertexManager );

speech.setBlendFunction( GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA );
speech.setScale( 0.5f );
speech.setAutoWrapWidth( 500f );
speech.setAutoWrap( AutoWrap.WORDS );
speech.setPosition( xVal, yVal );


The text is not displayed on screen on screen at all, I figure its the x and y location being wrong because when I manually set x and y to positions I know would be on the screen area it is shown. I am looking for help as how to get the actual X and Y coordinate of the body on screen so I can have the text follow the body.

Basically there are two engine right now working for your game.

1. Game Engine
2. Physics Engine

Game engine works on pixel coordinate system and physics engine works on meter coordinate system. So that you print body x and y, you get coordinate in meter, this thing already you are getting.

You have to use

PhysicsConstant.PIXEL_TO_METER_RATIO


to convert meter data into pixel data.

So to get actual x and y for you text related to player body you have to write following statement :

playerX = bodyA.getPosition().x * PhysicsConstant.PIXEL_TO_METER_RATIO;
playerY = bodyA.getPosition().y * PhysicsConstant.PIXEL_TO_METER_RATIO;
`

If you don't want to all these stuff then you can directly use sprite x and y coordinate.

• Thanks, that pushed me in the right direction. Still having some issues but trying to fix them one by one. – kabuto178 Sep 26 '13 at 18:30