做简单动画动画的好方法?

时间:2013-01-20 14:33:52

标签: java

// The "Animation" class.
import java.awt.*;
import hsa.Console;

public class Animation
{
    static Console c;           // The output console


    public static void main (String[] args) throws InterruptedException
    {
        c = new Console ();


        for (int index = 0 ; index < 300 ; index += 10)
        {



            // This is the night sky     
            c.setColor (Color.black);
            c.fillRect (0, 0, 1500, 700);
            c.drawRect (0, 0, 1500, 700);

            // This is the moon 
            c.setColor (Color.white);
            c.fillOval (550, 10, 80, 90);

            // These are the stars in the background 
            c.setColor (Color.yellow);
            c.fillStar (50, 70, 20, 20);
            c.fillStar (90, 100, 20, 20);
            c.fillStar (130, 70, 20, 20);
            c.fillStar (210, 70, 20, 20);
            c.fillStar (290, 70, 20, 20);
            c.fillStar (370, 70, 20, 20);
            c.fillStar (450, 70, 20, 20);
            c.fillStar (170, 100, 20, 20);
            c.fillStar (250, 100, 20, 20);
            c.fillStar (330, 100, 20, 20);
            c.fillStar (410, 100, 20, 20);

            // This is the shooting star 
            c.fillStar (index, index, index + 20, index + 10);

            Thread.sleep (1400);




        }

        // Place your program here.  'c' is the output console
    } // main method
} // Animation class

我们正在研究计算机科学的总结,其任务是利用我们在Java中的知识构建一个可以运行简单动画的程序。这是我到目前为止得到的代码问题是,流星不断变得越来越大,但我希望它保持1个大小,你有什么建议吗?

2 个答案:

答案 0 :(得分:0)

我认为这是因为您在indexwidth参数中使用了height。我还假设此API的Javadoc是here。如果是这样,我建议像:

c.fillStar(index, index, 20, 10);

答案 1 :(得分:0)

替换

        c.fillStar (index, index, index + 20, index + 10);

通过

        c.fillStar (index, index,  20,  10);