0
我試圖讓紅點直線向下移動y軸。請幫忙。現在它不動。我需要它在x = 235,y = 0處向下移動,直到x = 235,y = 235,以創建運動錯覺。這裏是代碼(因爲我從左邊的右邊改變了球的運動,所以很亂,但是不能讓它下移)。動畫:如何使圓/球直線向下移動y軸
import java.awt.Color;
import java.awt.Graphics;
public class Animation {
public static void main(String [] args) {
DrawingPanel panel = new DrawingPanel(350, 350);
Graphics g = panel.getGraphics();
background(g);
ballroll(panel, g);
}
public static void ballroll(DrawingPanel panel, Graphics g) {
//draw and roll the ball now
g.setColor(Color.RED);
int x = 245, y = 0, direction=1;
while(y<245){
g.fillOval(235, 0, 20, 20);
//if (x==0){
y+=60;
direction *= -1;
}
//else if (x < 115){
//direction *= -1;
//y+=60;
//}
y+=direction*15;
System.out.println(x);
panel.sleep(80);
}
panel.sleep(350);
//}
}
可能重複的[動畫:如何「向下滾動」y軸向下)(http://stackoverflow.com/questions/40582775/animation-how-to-roll-circle -down-the-y-axis) – Spektre
不要發佈重複的問題,而是添加新的信息作爲編輯到您的原始問題 – Spektre