1

我在标题中可怕地解释了这一点,我很抱歉,我对 Java 很陌生,还不太了解其中的一些内容。

无论如何,我的猫动画运行到屏幕中间,划伤两次,然后继续运行到最后,有没有写一个方法,将根据输入int num制作neko划伤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);
    }   
}
4

0 回答 0