PraveenMax
PraveenMax

Reputation: 717

In Libgdx, How to get the x,y coordinates on rotation for an image?

I have rotated an image in libgdx using this method,

SpriteBatch.draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)

But i dont know how to get the co-ordinates of the rotated image.

Upvotes: 1

Views: 1350

Answers (3)

P.T.
P.T.

Reputation: 25177

Instead of rotating the texture at draw time, you could use a Sprite (or your own object that tracks its current location).

The draw call doesn't store any of the rotation results, it just rotates the texture as its copied to the screen. The Sprite class will keep track of the location and rotation so you can query it. (You should use the Sprite's draw method to draw it.)

The Sprite will also give you an axis-aligned bounding box. If you want the precise location of the rotated corners of your texture, you'll need to extract it from getVerticies() or compute it yourself from the location and rotation.

Upvotes: 2

Michał Z.
Michał Z.

Reputation: 4119

Or better, you should rotate your image before drawing. If you do this, you can get rotation from your sprite/image object any time you want.

Upvotes: 1

TheWhiteLlama
TheWhiteLlama

Reputation: 1286

I don't get the question. I read it a few times, but I don't even get the core of what you want to know. If you are drawing an image with spriteBatch.draw(), your drawn image will be placed on the coorinates of the second and third parameter, and rotated/scaled around the relative origin.

If you want to know where the image is drawn on the screen, you should consider using camera.project(Vector3); with a 3 dimensional vector where x,y are your coordinates of your image and z = 0; The vector will be multiplied by the matrix of the camera, so that x,y will be the screen-coorinates.

Upvotes: 1

Related Questions