如果我理解正确的话,LibGDX是通过使用addActions方法来旋转图像的:
this.addAction( parallel(rotateBy(360, 0.5f), moveTo(320, 100, 0.5f)));
问题在于,图像正在被 点=(0,0) 旋转。
我的问题是:
是否有一种方法可以将图像按对象的 中心点 旋转?就像把它钉在中间,然后像车轮一样转动它?
rotateBy
和 rotateTo
方法都是以图像本身的 (0,0) 点旋转。
如果我理解正确的话,LibGDX是通过使用addActions方法来旋转图像的:
this.addAction( parallel(rotateBy(360, 0.5f), moveTo(320, 100, 0.5f)));
问题在于,图像正在被 点=(0,0) 旋转。
我的问题是:
是否有一种方法可以将图像按对象的 中心点 旋转?就像把它钉在中间,然后像车轮一样转动它?
rotateBy
和 rotateTo
方法都是以图像本身的 (0,0) 点旋转。
您需要正确设置角色的“原点”位置。从Actor API中可以了解到,该原点相对于位置而言,并用于缩放和旋转。
因此,请计算出您的中心点,并将原点设置为中心点。
Actor a;
....
a.setOrigin(a.getWidth()/2, a.getHeight()/2);
Actor a;
...
a.setOrigin(Align.center);
img.setorigin(width/2,hieght/2);
现在您可以根据需要顺时针和逆时针旋转:
img.rotate(2f);
或者
img.rotate(-2f);
x = this.getX();
y = this.getY();
cx = this.getWidth() * .5;
cy = this.getHeight() * .5;
this.translate(-(x+cx), -(y+cy)); // move so 0,0 is the centre of the Actor object
this.rotate(thisMuch); // rotate the Actor
this.translate((x+cx), (y+cy)); // move it back to its original location