タイトルで恐ろしく説明しましたが、申し訳ありませんが、Javaは初めてで、まだ一部を理解していません。
とにかく、私の猫のアニメーションは画面の中央まで実行され、2 回スクラッチされ、最後まで実行され続けます。とにかく、入力に応じint num
てネコをスクラッチする回数をパラメーターとして取るメソッドを作成することはできますか?x
どんな助けでも大歓迎です
これが私の現在のコードです
// Run the animation.
public void nekoRun() {
moveIn();
scratch();
//scratch2(5);
moveOut();
}
// Move Neko to the centre of the panel
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);
}
}
//neko stops and scratches in the middle of the panel twice
private void scratch() {
for (int i = 0; i < 10; i++) {
// Swap images.
currentImageIndex = nextImageList[currentImageIndex];
currentImage = nekoPics[currentImageIndex];
repaint();
pause(150);
}
}
//Neko runs to the end of the panel
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);
}
}