实现游戏开发中的屏幕滚动功能[2]

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

本文简介:

            input();
            drawScreen(g);
            try
            {
                Thread.sleep(delay);
            } catch (InterruptedException ie)
            {
            }
        }
    }

    // Method to Handle User Inputs
    private void input()
    {
        int keyStates = getKeyStates();

        if ((keyStates & LEFT_PRESSED) != 0)
        {
            if (scnX - 1 > 0)
                scnX--;
        }
        if ((keyStates & RIGHT_PRESSED) != 0)
        {
            if (scnX + 1 + 140 < backgroundImage.getWidth())
                scnX++;
        }
       
    }

    // Method to Display Graphics
    private void drawScreen(Graphics g)
    {

        g.setColor(0xffffff);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(0x0000ff);

        // display all layers
        layerManager.setViewWindow(scnX, scnY, 140, 140);
        layerManager.paint(g, 20, 20);

        flushGraphics();
    }

}


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class SimpleScrollingLayerManger extends MIDlet
{
    private Display display;

    public void startApp()
    {
        try
        {
            display = Display.getDisplay(this);
            ExampleGameCanvas gameCanvas = new ExampleGameCanvas();
            gameCanvas.start();
            display.setCurrent(gameCanvas);
        } catch (Exception ex)
        {
            System.out.println(ex);
        }
    }

    public Display getDisplay()
    {
        return display;
    }

    public void pauseApp()
    {
    }

    public void destroyApp(boolean unconditional)
    {
        exit();
    }

    public void exit()
    {
        System.gc();
        destroyApp(false);
        notifyDestroyed();
    }
}

本文关键:实现游戏开发中的屏幕滚动功能
  相关方案
Google
 

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

go top