本文整理汇总了Java中java.awt.image.BufferStrategy.show方法的典型用法代码示例。如果您正苦于以下问题:Java BufferStrategy.show方法的具体用法?Java BufferStrategy.show怎么用?Java BufferStrategy.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.BufferStrategy
的用法示例。
在下文中一共展示了BufferStrategy.show方法的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());
}
示例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();
}
示例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
}
示例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();
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}