【发布时间】:2017-10-10 08:09:58
【问题描述】:
我想一起旋转一组精灵、多边形和矩形。图 a) 显示了 2 个精灵,边界多边形和矩形。该组围绕大矩形的中心旋转 90 度(两个矩形的并集)。
以下代码创建图 b)。它不会围绕联合矩形的中心旋转精灵和多边形。
public void rotate(int rangle, float rotateX, float rotateY){
this.sprite.rotate(rangle);
this.polygon.rotate(rangle);
Polygon tempPoly = new Polygon(new float[] {
this.rectangle.x, this.rectangle.y,
this.rectangle.x, this.rectangle.y + this.rectangle.height,
this.rectangle.x + this.rectangle.width, this.rectangle.y + this.rectangle.height,
this.rectangle.x + this.rectangle.width, this.rectangle.y
});
tempPoly.setOrigin(rotateX, rotateY);
tempPoly.rotate(rangle);
this.rectangle = null;
this.rectangle = tempPoly.getBoundingRectangle();
}
以下代码创建图 c)。当我尝试将精灵和多边形移动到矩形位置时,存在未对齐的问题。
public void rotate(int rangle, float rotateX, float rotateY){
this.sprite.rotate(rangle);
this.polygon.rotate(rangle);
Polygon tempPoly = new Polygon(new float[] {
this.rectangle.x, this.rectangle.y,
this.rectangle.x, this.rectangle.y + this.rectangle.height,
this.rectangle.x + this.rectangle.width, this.rectangle.y + this.rectangle.height,
this.rectangle.x + this.rectangle.width, this.rectangle.y
});
tempPoly.setOrigin(rotateX, rotateY);
tempPoly.rotate(rangle);
this.rectangle = null;
this.rectangle = tempPoly.getBoundingRectangle();
// This tries to move them to rectangle
this.sprite.setPosition(this.rectangle.getX(), this.rectangle.getY());
this.polygon.setPosition(this.rectangle.getX(), this.rectangle.getY());
}
问题是如何在旋转后将精灵与矩形对齐(即类似于图a,角度=0)。 提示:问题的出现是因为精灵在绘制时会旋转,因此精灵和矩形之间存在未对齐的情况。 (link)
【问题讨论】:
标签: android opengl-es libgdx sprite