當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferStrategy類代碼示例

本文整理匯總了Java中java.awt.image.BufferStrategy的典型用法代碼示例。如果您正苦於以下問題:Java BufferStrategy類的具體用法?Java BufferStrategy怎麽用?Java BufferStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BufferStrategy類屬於java.awt.image包,在下文中一共展示了BufferStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
/**
 * Render offscreen graphics into the frame.
 */
private void render() {
    final BufferStrategy bufferStrategy = frame.getBufferStrategy();
    do {
        do {
            final Graphics2D graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
            // canvas is not opaque, so fill with background color
            graphics.setPaint(background);
            graphics.fillRect(0, 0, 400, 400);
            // then let canvas render into graphics
            canvas.render(graphics);
            graphics.dispose();
        } while (bufferStrategy.contentsRestored());
        bufferStrategy.show();
    } while (bufferStrategy.contentsLost());
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:19,代碼來源:OffscreenCanvasExample.java

示例2: onDraw

import java.awt.image.BufferStrategy; //導入依賴的package包/類
/**
 * Draw all game objects.
 */

private void onDraw() {
    BufferStrategy frameStrategy = frame.getBufferStrategy();
    if (frameStrategy == null) {
        // create the buffer strategy, its null.
        frame.createBufferStrategy(3);
        frameStrategy = frame.getBufferStrategy();
    }
    // clear and get our graphics object.
    graphics = frameStrategy.getDrawGraphics();
    graphics.clearRect(0, 0, width, height);

    if (showFPS) {
        graphics.setColor(Color.red);
        graphics.drawString(Integer.toString(fps) + " fps", 50, 50);
    }

    // update stack.
    stack.forEach(state -> state.onDraw(graphics));

    graphics.dispose();
    frameStrategy.show();

}
 
開發者ID:Vrekt,項目名稱:Lunar,代碼行數:28,代碼來源:Game.java

示例3: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
public void render() {
	//creates place for image to be rendered behind screen then shown
	BufferStrategy bs = getBufferStrategy();
	if (bs == null) {
		createBufferStrategy(3); //3 "screens"
		return;
	}

	screen.clear();
	int xScroll = player.x - screen.width / 2;
	int yScroll = player.y - screen.height / 2;
	level.render(xScroll, yScroll, screen);
	player.render(screen);

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

	Graphics g = bs.getDrawGraphics(); //linking buffer with graphics
	g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
	g.setColor(Color.WHITE);
	g.setFont(new Font("Verdena", 0, 20));
	g.drawString("X: " + (player.x >> 4) + ", Y: " + (player.y >> 4), 0, 16);
	g.dispose(); //remove graphics that are not used
	bs.show(); //swapping out the buffers
}
 
開發者ID:Samanimkr,項目名稱:KingdomKing,代碼行數:27,代碼來源:Game.java

示例4: update

import java.awt.image.BufferStrategy; //導入依賴的package包/類
@Override
public void update(RenderedFrame left, RenderedFrame right, DebugDrawer debugDrawer) {
    this.requestFocusInWindow();
    BufferStrategy bufferStrategy = getBufferStrategy();
    if (bufferStrategy == null) {
        createBufferStrategy(2);
        bufferStrategy = getBufferStrategy();
    }
    for (int row = 0; row < Screen.HEIGHT; row++) {
        for (int col = 0; col < Screen.WIDTH; col++) {
            imageData[col + Screen.WIDTH * row] = (left.getPixel(row, col) & 0xff) << 16 | (right.getPixel(row, col) & 0xff);
        }
    }
    Graphics g = bufferStrategy.getDrawGraphics();
    g.drawImage(bufferedImage, 0, 0, Screen.WIDTH * SCALE, Screen.HEIGHT * SCALE, null);
    if (debugDrawer != null) {
        debugDrawer.drawDebug(g, SCALE);
    }
    g.dispose();
    bufferStrategy.show();
}
 
開發者ID:gilles-duboscq,項目名稱:jvb,代碼行數:22,代碼來源:MergedScreen.java

示例5: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:BufferStrategyExceptionTest.java

示例6: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
private void render() {
	BufferStrategy bs = getBufferStrategy();
	if (bs == null) {
		createBufferStrategy(3);
		return;
	}
	Graphics2D g = (Graphics2D) bs.getDrawGraphics();
	screen.setGraphic(g);
	entityManager.renderByPixels(screen);
	for (int i = 0; i < pixels.length; i++) {
		pixels[i] = screen.getPixels()[i];
	}
	g.setStroke(new BasicStroke(2));
	g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
	entityManager.renderByGraphics(screen);
	screen.dispose();
	bs.show();
}
 
開發者ID:nguyen124,項目名稱:AutoDrivingCarUsingNeuronNetwork,代碼行數:19,代碼來源:CarDemo.java

示例7: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
private void render() {
	BufferStrategy bs = this.getBufferStrategy();
	if (bs == null) {
		createBufferStrategy(3);
		return;
	}
	screen.clear(ColorUtil.toARGBColor(Color.BLACK));
	gsm.render(screen);

	for (int i = 0; i < screen.getWidth() * screen.getHeight(); i++) {
		pixels[i] = screen.getPixels()[i];
	}

	Graphics g = bs.getDrawGraphics();
	g.setColor(Color.BLACK);
	g.fillRect(0, 0, this.getWidth(), this.getHeight());
	if (settings.fullscreen) {
		g.drawImage(img, fullScreenXOff, fullScreenYOff, fullScreenImageWidth, fullScreenImageHeight, null);
	} else {
		g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
	}
	g.dispose();
	bs.show();
}
 
開發者ID:Keabot-Studios,項目名稱:DungeonRun2,代碼行數:25,代碼來源:Game.java

示例8: start

import java.awt.image.BufferStrategy; //導入依賴的package包/類
public void start() {


        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();

        }
    }
 
開發者ID:deeplearning4j,項目名稱:DataVec,代碼行數:22,代碼來源:DrawReconstruction.java

示例9: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
private void render(){
	BufferStrategy bs = this.getBufferStrategy();
	if(bs == null){
		this.createBufferStrategy(3);
		return;
	}
	Graphics g = bs.getDrawGraphics();
	drawBackground(g); //TODO: fix it up? Background Images
	handler.render(g);
	if(gameState == STATE.Game){
		hud.render(g);	
		gun.render(g);
	}else if (gameState != STATE.Game){
		handler.clear();
		menu.render(g);
	}
	g.dispose();
	bs.show();
}
 
開發者ID:noxor0,項目名稱:marshmallow,代碼行數:20,代碼來源:Game.java

示例10: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
private void render() {
    BufferStrategy gameBS = this.getBufferStrategy();
    if (gameBS == null) {
        this.createBufferStrategy(3);
        return;
    }
    Graphics gameG = gameBS.getDrawGraphics();

    ///////////////DRAW GRAPHICS///////////////////
    gameG.setColor(Color.black); //TODO Replace Background Color with a Background Picture
    gameG.fillRect(0, 0, getWidth(), getHeight()); //background size
    handler.render(gameG);

    gameG.setColor(Color.white);
    gameG.drawString("| SCORE: " +
            handler.getScore() + " | HEALTH: " +
            handler.getHealth() + " | LEVEL: " +
            handler.getLevel() + " | MONEY: " +
            handler.getMoney() + " |", 15, 15);
    /////////////////////////////////////////////

    gameG.dispose();
    gameBS.show();
}
 
開發者ID:tsteinholz,項目名稱:OriginalSpaceShooter,代碼行數:25,代碼來源:Game.java

示例11: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }

    Graphics g = bs.getDrawGraphics();
    Graphics2D g2d = (Graphics2D) g;
    // At least on Ubuntu we seem not to need to translate the canvas
    if(!Util.isUnix())
        g2d.translate(-6, -28);
    ////////////////////////////////////////////////

    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, WIDTH, HEIGHT);

    stateManager.render(g2d);

    ////////////////////////////////////////////////
    g.dispose();
    bs.show();
}
 
開發者ID:BossLetsPlays,項目名稱:Firestorm,代碼行數:24,代碼來源:Game.java

示例12: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
/**
 * Kümmert sich um die BufferStrategy und delegiert das 
 * zeichnen der Sprites direkt an die Sprites selbst.
 * 
 */
public void render() {
	BufferStrategy bs = getBufferStrategy();
	if(bs == null) {
		try {
		createBufferStrategy(3);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return;
	}
	
	Graphics g = bs.getDrawGraphics();
	game.drawAll(image.getGraphics());
	g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
	
	g.dispose();
	bs.show();
}
 
開發者ID:HSR-SE2Proj,項目名稱:JBomberman,代碼行數:24,代碼來源:GameCanvas.java

示例13: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
@Override
public void render() {
	if (!running) return;

	BufferStrategy bs = canvas.getBufferStrategy();
	if (bs == null) {
		canvas.createBufferStrategy(3);
		return;
	}
	Graphics g = bs.getDrawGraphics();

	g.setColor(Color.BLACK);
	g.fillRect(0, 0, this.size.width, this.size.height);

	this.graphics = g;

	this.getGame().onRender();
	this.getGame().onPostRender();

	this.graphics = null;

	g.dispose();
	bs.show();
}
 
開發者ID:cubedtear,項目名稱:aritzh,代碼行數:25,代碼來源:CanvasEngine.java

示例14: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }
    Graphics g = bs.getDrawGraphics();
    if (state == GameState.LOADING) LoadScreen.render(g);
    if (state == GameState.MENU) menu.render(g);
    if (state == GameState.CREDITS) credits.render(g);
    if (state == GameState.ABOUT) about.render(g);
    if (state == GameState.CONTROLS) controlScreen.render(g);
    if (state == GameState.GAMEOVER) endScreen.render(g);
    renderGame(g);
    g.dispose();
    bs.show();
}
 
開發者ID:BossLetsPlays,項目名稱:StickJumper,代碼行數:18,代碼來源:Game.java

示例15: render

import java.awt.image.BufferStrategy; //導入依賴的package包/類
public void render() {
	BufferStrategy bs = this.getBufferStrategy();
	
	if (bs == null) {
		this.createBufferStrategy(DystopiaCanvas.BUFFERS);
		this.requestFocus();
		return;
	}

	Graphics2D g = (Graphics2D) bs.getDrawGraphics();
	
	g.setColor(new Color(0xEEEEEE));
	g.fillRect(0, 0, DisplayCarrier.getCanvas().getWidth(), DisplayCarrier.getCanvas().getHeight());
	GridDisplay.drawGrid(g);
	Rectangle2D rect = new Rectangle2D.Double(DisplayCarrier.getCanvas().getWidth() / 2 - Tile.getTileSize(), DisplayCarrier.getCanvas().getHeight() / 2 - Tile.getTileSize(), Tile.getTileSize() * 2, Tile.getTileSize() * 2);
	g.draw(rect);
	PlayerCamera.drawPlayer(g);
	
       g.dispose();
       
       if (!bs.contentsLost()) {
       	bs.show();
       }
       Toolkit.getDefaultToolkit().sync();
}
 
開發者ID:wbtafrier,項目名稱:Dystopia,代碼行數:26,代碼來源:DystopiaCanvas.java


注:本文中的java.awt.image.BufferStrategy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。