Package java.awt.image

Examples of java.awt.image.BufferStrategy



    int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    boolean running = true;
    while(running){
      BufferStrategy bs = frame.getBufferStrategy();
      if(bs==null){
        frame.createBufferStrategy(4);
        return;
      }
      for (int i = 0; i < width * height; i++)
        pixels[i] = 0;

      Graphics g= bs.getDrawGraphics();
      g.drawImage(img, heightOffset, widthOffset, width, height, null);
      g.dispose();
      bs.show();

    }
  } 
View Full Code Here



    int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
    boolean running = true;
    while(running){
      BufferStrategy bs = frame.getBufferStrategy();
      if(bs==null){
        frame.createBufferStrategy(4);
        return;
      }
      for (int i = 0; i < width * height; i++)
        pixels[i] = 0;

      Graphics g= bs.getDrawGraphics();
      g.drawImage(img, heightOffset, widthOffset, width, height, null);
      g.dispose();
      bs.show();

    }
  }
View Full Code Here

   
  }
 
  // rendering while the component updates
  public void render() {
    BufferStrategy bs = getBufferStrategy();
    if(bs == null) {
      this.createBufferStrategy(3);
      return;
    }
   
    // set the graphics to the buffer strategy image
    Graphics g = bs.getDrawGraphics();
    // draw the canvas image
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
    // dispose gfx and draw buffer
    g.dispose();
    bs.show();
  }
View Full Code Here

        tickCount++;
        level.tick();
    }

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

        int xOffset = player.x - (screen.width / 2);
        int yOffset = player.y - (screen.height / 2);

        level.renderTiles(screen, xOffset, yOffset);
        level.renderEntities(screen);

        for (int y = 0; y < screen.height; y++) {
            for (int x = 0; x < screen.width; x++) {
                int colourCode = screen.pixels[x + y * screen.width];
                if (colourCode < 255)
                    pixels[x + y * WIDTH] = colours[colourCode];
            }
        }

        Graphics g = bs.getDrawGraphics();
        g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
        g.dispose();
        bs.show();
    }
View Full Code Here

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

  }
 
  public void update() {
    Window w = vc.getFullScreenWindow();
    if(w != null) {
      BufferStrategy s = w.getBufferStrategy();
      if(!s.contentsLost()) {
        s.show();
      }
    }
  }
View Full Code Here

 
 
 
  public void render()
  {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
      createBufferStrategy(2);
      return;
    }
    Graphics2D g = (Graphics2D) bs.getDrawGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, WIDTH, HEIGHT);
    //////////////////// DRAW GAME SCREEN ////////////////////
    leftPowerUp.draw(g);
    topBound.draw(g);
    bottomBound.draw(g);
    leftBound.draw(g);
    rightBound.draw(g);
    leftPlayer.draw(g);
    rightPlayer.draw(g);
    ballSpawner.draw(g);
    for (int i = 0; i < activeBalls.size(); i++)
    {
      activeBalls.get(i).draw(g);
    }
    drawText(g);
    //////////////////////////////////////////////////////////
    Toolkit.getDefaultToolkit().sync();
    g.dispose();
    bs.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

  }

  @Override
  public void run() {
    if ( this.isDrawable() ) {
      BufferStrategy bs;
      Graphics2D g2;
      boolean mustCreateBuffer;

      do {
        g2 = null;
        mustCreateBuffer = false;
        bs = this.getBufferStrategy();

        if ( bs == null ) {
          if ( ! this.isDrawable() ) {
            return;
          }
          mustCreateBuffer = true;
        } else {

          g2 = this.getStrategyGraphics( bs );
          if ( g2 == null ) {
            return;
          }
        }

        if ( mustCreateBuffer ) {
          if ( ! this.createBufferStrategy() ) {

            return;
          }
        }

        if ( bs == null ) {
          bs = this.getBufferStrategy();

        }

        try {

          if ( g2 == null ) {
            this.readLock.lock();
            try {
              g2 = (Graphics2D) ( ( bs == null ) ? this.drawingCanvas.getGraphics() : this.getStrategyGraphics( bs ) );
            } finally {
              this.readLock.unlock();
            }
          }
          if ( g2 != null ) {
            g2.setColor( this.drawingCanvas.getBackground() );
            g2.fillRect( 0, 0, this.drawingCanvas.getWidth(), this.drawingCanvas.getHeight() );
            g2.setColor( this.drawingCanvas.getForeground() );
            this.doDraw( g2 );
            this.applyFadeoutEffect( g2, this.getFadeoutStartTime() );
          }
        } catch ( Exception e ) {
          this.setError( e );
          this.doCallback( this.getObservers() );
          return;
        } finally {
          if ( g2 != null && bs != null ) {
            g2.dispose();
          }
        }

        if ( bs != null ) {
          bs.show();
        }

      } while ( bs != null && bs.contentsLost() && this.isDrawable() );

    }
  }
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.