使用GameCanvas制作星空效果[4]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

            graphics.copyArea(0, 0, w, h, 0, 1, Graphics.TOP | Graphics.LEFT);
            graphics.setColor(0, 0, 0);
            graphics.drawLine(0, 0, w, 0);
            graphics.setColor(255, 255, 255);
            for (int i = 0; i < w; ++i)
            {
                int test = Math.abs(random.nextInt()) % 100;
                if (test < 5)
                {
                    graphics.drawLine(i, 0, i, 0);
                }
            }
            flushGraphics();

            // Now wait...

            try
            {
                Thread.sleep(sleepTime);
            } catch (InterruptedException e)
            {
            }
        }
    }

    // When the canvas is shown, start a thread to
    // run the game loop.

    protected void showNotify()
    {
        random = new Random();
        thread = new Thread(this);
        thread.start();
    }
    // When the game canvas is hidden, stop the thread.

本文关键:使用GameCanvas制作星空效果
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top