本文整理匯總了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();
}