JME 배우기 - 4(SimpleGame분석)

2008. 5. 28. 11:10Java

드뎌 SimpleGame이다.

이건 소스를 분석해야.. -0-

일단 소스파일을 첨부한다. 개발할때는 항상 라이브러리 뿐만아니라, 소스도 첨부해서 같이 보는습관을 들이자.

정말 정말 도움이된다.


SimpleGame 클래스 에 선언되어 있는 변수인데, 카메라, 노드, 입력, 타이머, 폰트 등등에 대한 기본설정이 되어있다.

  /** The camera that we see through. */
  protected Camera cam;


    /** The root of our normal scene graph. */
  protected Node rootNode;


    /** Handles our mouse/keyboard input. */
  protected InputHandler input;


    /** High resolution timer for jME. */
  protected Timer timer;


    /** The root node of our text. */
  protected Node fpsNode;


    /** Displays all the lovely information at the bottom. */
  protected Text fps;


    /** Simply an easy way to get at timer.getTimePerFrame().  Also saves time so you don't call it more than once per frame. */
  protected float tpf;


    /** True if the renderer should display bounds. */
  protected boolean showBounds = false;



    /** A wirestate to turn on and off for the rootNode */
  protected WireframeState wireState;


광원인듯.
    /** A lightstate to turn on and off for the rootNode */
  protected LightState lightState;


폰트 위치네, 내부적으로 폰트를 제공한다. 나중에 우리만의 폰트로 갈아치울수 있을듯.


    /** Location of the font for jME's text at the bottom */
  public static String fontLocation = "com/jme/app/defaultfont.tga";



  /** This is used to display print text. */
  protected StringBuffer updateBuffer=new StringBuffer(30);


  /** This is used to recieve getStatistics calls.*/
  protected StringBuffer tempBuffer=new StringBuffer();


 protected boolean pause;





또한 소스를 보면 정말 백과사전이다. 다 설명되어 있다. 말이 필요없을정도.


1. protected final void update(float interpolation) : BaseGame.start()이 호출될때 실행한다. 주임무는, 매프레임마다 키입력에 대한 렌더링 상태를 설정한다는것이다.


2. protected final void render(float interpolation)  : update후에 바로 실행된다. 말그대로 설정된 상태에 따라 렌더링


3. protected final void initSystem() : BaseGame.start()가 호출된직후 직접적으로 호출된다. 디스플레이, 카메라 설정, 키설정 을 한다. 참 키설정은 다음과 같이하네.


  KeyBindingManager.getKeyBindingManager().set(
    "toggle_pause",
    KeyInput.KEY_P);

   p에 대한 키를 toggle_pause 로 설정했다.


4. cleanup(): 소스를 보니 키보드및 마우스 입력에 대한 설정내용을 초기화한다.

      LoggingSystem.getLogger().log(Level.INFO, "Cleaning up resources.");

    if (InputSystem.getKeyInput() != null)
      InputSystem.getKeyInput().destroy();


    if (InputSystem.getMouseInput() != null)
      InputSystem.getMouseInput().destroy();


5. 마지막으로 다음이 있다.


  protected abstract void simpleInitGame();  => initGame() 뒤에 바로 호출, 반드시 구현해야함


  protected void simpleUpdate() {}  => update 메소드 후에 호출된다.


  protected void simpleRender() {}   ==> render에서 호출한다.


  위 3개는 이 SimpleGame 를 상속받아 처리하는 클래스에서 재정의 해서 사용해야 한다.



솔직히 위의 내용은 소스에 다 있다. 그냥 공부하면서 다시 써본것일뿐. =0=

어디 JME 서적없나. 킁