Search in sources :

Example 6 with BufferStrategy

use of java.awt.image.BufferStrategy in project cardgame1 by joey101937.

the class Board method render.

public void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
        // /run once at the start
        this.createBufferStrategy(3);
        return;
    }
    Graphics gr = bs.getDrawGraphics();
    Graphics2D g = (Graphics2D) gr;
    g.scale(xScale, yScale);
    g.setColor(Color.white);
    // render options gear
    g.drawImage(Main.BackgroundImage, 0, 0, null);
    g.setFont(new Font("Arial", Font.BOLD, 35));
    renderHeros(g);
    renderMinions(g);
    renderPlayerHand(g);
    renderEnemyHand(g);
    renderTraps(g);
    g.drawImage(SpriteHandler.gearSmall, 0, 0, null);
    this.visHandler.render(g);
    g.dispose();
    bs.show();
}
Also used : Graphics(java.awt.Graphics) BufferStrategy(java.awt.image.BufferStrategy) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 7 with BufferStrategy

use of java.awt.image.BufferStrategy in project 2D-Game-Engine by vanZeben.

the class Game method render.

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();
}
Also used : Graphics(java.awt.Graphics) BufferStrategy(java.awt.image.BufferStrategy)

Example 8 with BufferStrategy

use of java.awt.image.BufferStrategy in project grounded by alejolp.

the class GameCanvas method paint.

@Override
public void paint(Graphics arg0) {
    Game g = Game.getInstance();
    BufferStrategy bs = getBufferStrategy();
    int x, y, px, py;
    if (bs == null) {
        loadGraphics();
        return;
    }
    g2d = (Graphics2D) bs.getDrawGraphics();
    for (y = 0, py = 0; y < g.map.H; ++y, py += Constants.TILE_SIZE) {
        for (x = 0, px = 0; x < g.map.W; ++x, px += Constants.TILE_SIZE) {
            drawTileNum((g.map.data[y][x] == '.') ? Constants.ID_WALL : Constants.ID_BACKGROUND, px, py);
        }
    }
    drawObjects(g.map.items);
    drawObjects(g.map.exits);
    drawObjects(g.map.elevators);
    drawObjects(g.map.zombies);
    drawObjects(g.map.fireballs);
    drawObjects(g.map.specials);
    drawTileNum(Constants.ID_PLAYER, g.p.x, g.p.y);
    g2d.dispose();
    if (!bs.contentsLost()) {
        bs.show();
    } else {
        loadGraphics();
    }
}
Also used : BufferStrategy(java.awt.image.BufferStrategy)

Aggregations

BufferStrategy (java.awt.image.BufferStrategy)8 Graphics (java.awt.Graphics)5 Button (java.awt.Button)1 Canvas (java.awt.Canvas)1 Component (java.awt.Component)1 Dialog (java.awt.Dialog)1 DisplayMode (java.awt.DisplayMode)1 Font (java.awt.Font)1 Frame (java.awt.Frame)1 Graphics2D (java.awt.Graphics2D)1 GraphicsDevice (java.awt.GraphicsDevice)1 Panel (java.awt.Panel)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Robot (java.awt.Robot)1 Window (java.awt.Window)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 BufferedImage (java.awt.image.BufferedImage)1 DataBufferInt (java.awt.image.DataBufferInt)1