Package java.awt.image

Examples of java.awt.image.BufferStrategy


        }

        @Override
        public synchronized void relinquishVsync(BufferStrategy bs) {
            if (strategy != null) {
                BufferStrategy b = strategy.get();
                if (b == bs) {
                    strategy.clear();
                    strategy = null;
                }
            }
View Full Code Here


  }

  @Override
  public void render(Iterable<Component> components) {

    BufferStrategy bufferStrategy = this.canvas.getBufferStrategy();
    Graphics2D graphics = (Graphics2D)bufferStrategy.getDrawGraphics();
   
    try {

      graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      this.clearScreen(graphics);
     
      for(Component component : components) {
        component.render(graphics);
      }

      bufferStrategy.show();

    } finally {
      graphics.dispose();
    }
View Full Code Here

    level.add(player);

  }

  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      requestFocus();
      return;
    }

    int xScroll = player.x - screen.w / 2;
    int yScroll = player.y - (screen.h - 8) / 2;
    if (xScroll < 16) xScroll = 16;
    if (yScroll < 16) yScroll = 16;
    if (xScroll > level.w * 16 - screen.w - 16) xScroll = level.w * 16 - screen.w - 16;
    if (yScroll > level.h * 16 - screen.h - 16) yScroll = level.h * 16 - screen.h - 16;
    if (currentLevel > 3) {
      int col = Color.get(20, 20, 121, 121);
      for (int y = 0; y < 14; y++)
        for (int x = 0; x < 24; x++) {
          screen.render(x * 8 - ((xScroll / 4) & 7), y * 8 - ((yScroll / 4) & 7), 0, col, 0);
        }
    }

    level.renderBackground(screen, xScroll, yScroll);
    level.renderSprites(screen, xScroll, yScroll);

    if (currentLevel < 3) {
      lightScreen.clear(0);
      level.renderLight(lightScreen, xScroll, yScroll);
      screen.overlay(lightScreen, xScroll, yScroll);
    }

    renderGui();

    if (!hasFocus()) renderFocusNagger();

    for (int y = 0; y < screen.h; y++) {
      for (int x = 0; x < screen.w; x++) {
        int cc = screen.pixels[x + y * screen.w];
        if (cc < 255) pixels[x + y * WIDTH] = colors[cc];
      }
    }

    Graphics g = bs.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());

    int ww = WIDTH * 3;
    int hh = HEIGHT * 3;
    int xo = (getWidth() - ww) / 2;
    int yo = (getHeight() - hh) / 2;
    g.drawImage(image, xo, yo, ww, hh, null);
    g.dispose();
    bs.show();
  }
View Full Code Here

  }
 
  public Graphics2D getGraphics() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      return (Graphics2D) strategy.getDrawGraphics();
    } else {
      return null;
    }
  }
View Full Code Here

  }
 
  public void update() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      if (!strategy.contentsLost()) {
        strategy.show();
      }
    }
   
    // Sync the display on some systems. On Linux, this fixes event queue problems.
    Toolkit.getDefaultToolkit().sync();
View Full Code Here

      }
    }
  }
 
  private void render() {
    BufferStrategy strategy = getBufferStrategy();
    if (strategy == null) {
      createBufferStrategy(3);
      requestFocus();
      return;
    }
   
    paintComponent(getGraphics2D());

    Graphics g = strategy.getDrawGraphics();
    g.fillRect(0, 0, getWidth(), getHeight());

    int x = (getWidth() - getHeight())/2;
    g.drawImage(image, x, 0, getHeight(), getHeight(), this);
   
    g.dispose();
    strategy.show();
  }
View Full Code Here

   * The application must dispose of the graphics object.
   */
  public Graphics2D getGraphics() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      return (Graphics2D) strategy.getDrawGraphics();
    } else {
      return null;
    }
  }
View Full Code Here

   * Updates the display.
   */
  public void update() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
      BufferStrategy strategy = window.getBufferStrategy();
      if (!strategy.contentsLost()) {
        strategy.show();
      }
    }
    // Sync the display on some systems.
    // (on Linux, this fixes event queue problems)
    Toolkit.getDefaultToolkit().sync();
View Full Code Here

    game.tick();
  }

  private void render()
  {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null)
    {
      createBufferStrategy(3);
      return;
    }

    screen.render(game);

    for (int i = 0; i < WIDTH * HEIGHT; i++)
    {
      pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(img, 0, 0, WIDTH + 10, HEIGHT + 10, null);
    g.dispose();
    bs.show();

  }
View Full Code Here

      updateFrame();
    }
  }

  private void renderMenu() throws IllegalStateException {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(3);
      return;
    }

    Graphics g = bs.getDrawGraphics();
    try {
      g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/launcher.png")), 0, 0, 800, 400, null);
      if (InputHandler.MouseX > 690 && InputHandler.MouseX < 690 + 80 && InputHandler.MouseY > 130 && InputHandler.MouseY < 130 + 30) {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/play_on.png")), 690, 130, 80, 30, null);
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/arrow.png")), 770, 132, 20, 20, null);
        if(InputHandler.Mouse[1]) {
          dispose();
          new RunGame();
        }
      } else {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/play_off.png")), 690, 130, 80, 30, null);
      }

      if (InputHandler.MouseX > 650 && InputHandler.MouseX < 650 + 120 && InputHandler.MouseY > 165 && InputHandler.MouseY < 165 + 30) {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/options_on.png")), 650, 165, 120, 30, null);
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/arrow.png")), 770, 167, 20, 20, null);
        if(InputHandler.Mouse[1]) {
            new Options();
        }
      } else {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/options_off.png")), 650, 165, 120, 30, null);
      }

      if (InputHandler.MouseX > 698 && InputHandler.MouseX < 698 + 70 && InputHandler.MouseY > 200 && InputHandler.MouseY < 200 + 30) {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/help_on.png")), 698, 200, 70, 30, null);
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/arrow.png")), 770, 202, 20, 20, null);
        if(InputHandler.Mouse[1]) {
          //TODO add action code
        }
      } else {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/help_off.png")), 698, 200, 70, 30, null);
      }

      if (InputHandler.MouseX > 700 && InputHandler.MouseX < 700 + 80 && InputHandler.MouseY > 235 && InputHandler.MouseY < 235 + 30) {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/quit_on.png")), 700, 235, 70, 30, null);
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/arrow.png")), 770, 237, 20, 20, null);
        if(InputHandler.Mouse[1]) {
          System.exit(0);
        }
      } else {
        g.drawImage(ImageIO.read(Launcher.class.getResource("/menu/quit_off.png")), 702, 235, 70, 30, null);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
    bs.show();
  }
View Full Code Here

TOP

Related Classes of java.awt.image.BufferStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.