为什么我的rect
在draw()
期间不会轮换?
当我启用box2d
调试时,我看到实际的box2d对象正确旋转,但实际渲染的形状不会旋转..
Tween.to(getPlayer(), ShapeAccessor.ANGLE, 0.7f)
.target(0.4f)
.ease(Elastic.OUT)
.repeatYoyo(0, 0)
.start(getLevel().getTweenManager());
Player
具有以下draw()
方法..
public void draw(ShapeRenderer sRenderer, Vector2 pos) {
sRenderer.begin(ShapeType.Filled);
sRenderer.setColor(getColor().r, getColor().g, getColor().b, getColor().a);
sRenderer.identity();
sRenderer.rotate(0, 0, 1, getAngle());
sRenderer.translate(pos.x - getWidth(), pos.y - getHeight(), 0);
sRenderer.rect(0, 0, getWidth() * 2, getHeight() * 2);
sRenderer.end();
}
继承我的TweenAccessor
..
public class ShapeAccessor implements TweenAccessor<Shape> {
public static final int ANGLE = 5;
public int getValues(Shape target, int tweenType, float[] returnValues) {
switch (tweenType) {
case ANGLE: // animate object by rotation
returnValues[0] = ((Shape) target).getBody().getAngle();
return 1;
default:
assert false;
return -1;
}
}
public void setValues(Shape target, int tweenType, float[] newValues) {
switch (tweenType) {
case ANGLE: // animate object by rotation
((Shape) target).getBody().setTransform(
((Shape) target).getBody().getPosition(),
newValues[0]);
break;
default:
assert false;
}
}
}
答案 0 :(得分:0)
需要按60
向上缩放角度并修改.rect
坐标..
sRenderer.begin(ShapeType.Filled);
sRenderer.setColor(getColor().r, getColor().g, getColor().b, getColor().a);
sRenderer.identity();
sRenderer.translate(pos.x, pos.y, 0);
sRenderer.rotate(0, 0, 1, getBody().getAngle() * 60.0f);
sRenderer.rect(-getWidth(), -getHeight(), getWidth() * 2, getHeight() * 2);
sRenderer.end();