简体   繁体   English

在Libgdx中,如何获取图像旋转的x,y坐标?

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

I have rotated an image in libgdx using this method, 我使用这种方法在libgdx中旋转了一个图像,

SpriteBatch.draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) SpriteBatch.draw(TextureRegion区域,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. 但我不知道如何获得旋转图像的坐标。

Instead of rotating the texture at draw time, you could use a Sprite (or your own object that tracks its current location). 您可以使用Sprite (或跟踪其当前位置的自己的对象),而不是在绘制时旋转纹理。

The draw call doesn't store any of the rotation results, it just rotates the texture as its copied to the screen. draw调用不存储任何旋转结果,它只是将纹理旋转到复制到屏幕上。 The Sprite class will keep track of the location and rotation so you can query it. Sprite类将跟踪位置和旋转,以便您可以查询它。 (You should use the Sprite 's draw method to draw it.) (你应该使用Spritedraw方法来绘制它。)

The Sprite will also give you an axis-aligned bounding box. Sprite还会为您提供一个轴对齐的边界框。 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. 如果您想要纹理旋转角的精确位置,则需要从getVerticies()提取它,或者从位置和旋转中getVerticies()计算。

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. 如果使用spriteBatch.draw()绘制图像,则绘制的图像将放置在第二个和第三个参数的坐标上,并围绕相对原点旋转/缩放。

If you want to know where the image is drawn on the screen, you should consider using camera.project(Vector3); 如果你想知道在屏幕上绘制图像的位置,你应该考虑使用camera.project(Vector3); with a 3 dimensional vector where x,y are your coordinates of your image and z = 0; 使用3维向量,其中x,y是图像的坐标,z = 0; The vector will be multiplied by the matrix of the camera, so that x,y will be the screen-coorinates. 矢量将乘以相机的矩阵,因此x,y将是屏幕坐标。

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. 如果这样做,您可以随时从精灵/图像对象进行旋转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM