当前位置: 首页>>代码示例>>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;未经允许,请勿转载。