Java围绕中心点旋转对象?

时间:2015-07-04 12:06:43

标签: java

您好我正在制作一个节目,向您展示太空中不同的行星。 我在窗户的中心和周围的所有行星都有太阳。 我希望行星围绕太阳旋转,但我不知道如何做到这一点。请帮我。这是我将行星和太阳绘制到屏幕上的代码:

public class Solar1 extends BasicSystem {

private Image img;

public int px = 300,py = 300,px1 = 200,py1 = 200;


public Solar1() {

}

public void tick() {

}

public void render(Graphics g) {

    ImageIcon i = new ImageIcon("res/bg/bg1.png");
    img = i.getImage();
    g.drawImage(img, 0,0, null);

    ImageIcon i2 = new ImageIcon("res/planets/sun.png");
    img = i2.getImage();
    g.drawImage(img, Comp.size.width / 2 - 50, Comp.size.height / 2 - 50, null);

    ImageIcon i12 = new ImageIcon("res/planets/blue.png");
    img = i12.getImage();
    g.drawImage(img, px,py, null);

    ImageIcon i1112 = new ImageIcon("res/planets/green.png");
    img = i1112.getImage();
    g.drawImage(img, px1,py1, null);

}

}

1 个答案:

答案 0 :(得分:0)

        int i=0;

        while(true){
            planet1.setX(Math.cos(Math.toRadians(i)))*widthOfFrame;         
            planet1.setY(Math.sin(Math.toRadians(i)))*heightOfFrame;
            i++;
        }

...其中i是迭代次数。您还需要了解如何设置速度,距中心点的距离等...

相关问题