0

如何绘制一个形状,然后使用 jbox2D 和 swing 移动?

我可以绘制它,但是当我移动时,会显示旧形状。

谢谢你

public class DrawShape extends DebugDraw {
private Graphics graphics;

    public DrawShape(Graphics graphics) {
        super(new OBBViewportTransform());          
        this.graphics = graphics;
    }

    public void drawCircle(Vec2 center, float radius, Color3f color) {
        graphics.fillOval((int) (center.x - (radius / 2)), (int) (center.y - (radius / 2)), (int) radius, (int) radius);
        graphics.setColor(Color.BLACK);
    }
}
4

1 回答 1

1
  1. 您的绘图可能有误。一个类几乎不应该有一个 Graphics 字段。
  2. 我假设您正在绘制其中一种绘制方法,或者paint(Graphics g)(不要这样做),或者paintComponent(Graphics g)在 JComponent 派生类中(是的,使用这个)。如果是这样,您不太可能在此方法覆盖中调用超级方法。
于 2013-12-01T15:34:35.477 回答