-2
我正在嘗試對角色進行動畫製作,但我不太確定如何讓sleep()
工作。這個想法是,圖像每秒都會改變,直到動畫結束。截至目前,如果您按空格鍵,動畫應該運行。這是我到目前爲止:Java等待中的麻煩
Image[] imageArray = new Image[4];
imageArray[0] = getImage(getDocumentBase(), "Death1.png");
imageArray[1] = getImage(getDocumentBase(), "Death2.png");
imageArray[2] = getImage(getDocumentBase(), "Death3.png");
imageArray[3] = getImage(getDocumentBase(), "Death4.png");
for(int i = 1; i <= 4; i++) { //Or any Loops
try {
//player is just where the image is stored & painted
player = imageArray[i];
repaint();
Thread.sleep(1000);
}
catch (InterruptedException ex) {}
}
如果我沒有解釋得很好,請告訴我!我是新來的:-) –
我認爲你真正需要的是在「Swing」和「Thread.sleep」上進行搜索 - 你可能會將其指向諸如[Swing中的併發性](https) ://docs.oracle.com/javase/tutorial/uiswing/concurrency/)和[如何使用Swing Timers](https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html),因爲這個問題每天會被問到6次,答案几乎總是相同 – MadProgrammer
[示例搜索](http://stackoverflow.com/search?q=%5Bjava%5D+%5Bswing%5D+thread.sleep) – MadProgrammer