對此有點困惑,所以我想我會發布。對不起,如果我的標題不清楚,對Java很新,不知道如何解釋它。反正這裏是我的代碼集到目前爲止(問題位我猜)停止執行方法轉移到下一個方法
int currentImageIndex = 0; // Assuming [0] is your first image.
int[] nextImageList = { 2, 4, 5, 4, 5, 4, 5, 0, 1 };
public void nekoRun() {
moveIn();
scratch();
moveOut();
private void moveIn() {
for (int i = 0; i < getWidth()/2; i+=10) {
xPos = i;
// swap images
if (currentImage == nekoPics[0])
currentImage = nekoPics[1];
else
currentImage = nekoPics[0];
repaint();
pause(150);
private void scratch() {
for (int i = xPos; i < getWidth();) {
xPos = i;
// Swap images.
currentImageIndex = nextImageList[currentImageIndex];
currentImage = nekoPics[currentImageIndex];
repaint();
pause(150);
}
}
private void moveOut() {
for (int i = xPos; i < getWidth(); i+=10) {
xPos = i;
// swap images
if (currentImage == nekoPics[0])
currentImage = nekoPics[1];
else
currentImage = nekoPics[0];
repaint();
pause(150);
}
}
所以基本上會發生什麼(這是不是所有的代碼只是「多汁的部分」,貓就會在屏幕上運行,然後坐着,它應該劃傷兩次,我得到了一些與陣列有關的幫助,因爲我只是使用一堆其他的if語句,而且我知道這是多餘的。貓會跑到中心,它會劃傷,並保持因爲顯而易見的原因,在一個循環中抓撓,我只是困惑於如何讓它移動到moveOut方法上,而不是保持循環的方式。對不起,如果這有點不清楚,我很新,所以忍受着我
在此先感謝
正如一邊,你考慮重新命名你的'scratch()'方法'scratchTwice()'。這在這裏並不重要,但我相信你可以看到具有方法名稱的價值,這些名稱可以在更大和更復雜的系統中反映*它們的功能。 – Edd 2013-02-22 14:14:17