示例#1
0
  @Override
  public void init() {
    // TODO test BufferStrategy
    window.createBufferStrategy(2);
    strategy = window.getBufferStrategy();

    // TODO key listener
    //        window.addKeyListener();

    gsm.init();
  }
示例#2
0
  @Override
  public void render() {
    if (!window.isFocused()) {
      return;
    }
    // Render single frame
    do {
      // The following loop ensures that the contents of the drawing buffer
      // are consistent in case the underlying surface was recreated
      do {
        // Get a new graphics context every time through the loop
        // to make sure the strategy is validated
        Graphics2D g2 = (Graphics2D) strategy.getDrawGraphics();

        // Clear rect
        g2.clearRect(0, 0, window.getWidth(), window.getHeight());
        // Render to graphics
        gsm.render(g2);
        // ...

        if (SHOW_INFO) {
          g2.setPaint(Color.WHITE);
          g2.drawString(renderThread.report(), 900, 18);
          g2.drawString(updateThread.report(), 1100, 18);
        }

        // Dispose the graphics
        g2.dispose();

        // Repeat the rendering if the drawing buffer contents
        // were restored
      } while (strategy.contentsRestored());

      // Display the buffer
      strategy.show();

      // Repeat the rendering if the drawing buffer was lost
    } while (strategy.contentsLost());
  }
示例#3
0
 @Override
 public void update() {
   gsm.update();
 }
示例#4
0
 @Override
 public void processInput() {
   gsm.processInput(null);
 }