是否可以在沒有任何遊戲引擎的情況下簡單地在java(swing)中進行360度移動?我只有這樣的嘗試:java中的360度移動示例
public class Game extends JPanel implements Runnable {
int x = 300;
int y = 500;
float angle = 30;
Game game;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.add(new Game());
frame.setSize(600, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Game() {
setSize(600, 600);
Thread thread = new Thread(this);
thread.start();
}
@Override
public void paint(Graphics g) {
g.setColor(Color.WHITE);
g.drawRect(0, 0, 600, 600);
g.setColor(Color.CYAN);
g.fillOval(x, y, 10, 10);
g.dispose();
}
@Override
public void run() {
while(true) {
angle += -0.1;
x += Math.sin(angle);
y--;
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ex) {}
}
}
}
,你可以在下面的圖片中看到,我不知道如何處理的運動旋轉,這是輸出:
image http://screenshot.cz/GOXE3/mvm.jpg
我沒有做3D圖形,檢查圖像。 – Pink 2014-11-22 12:24:50