/**
* 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();
}
java类java.awt.image.BufferStrategy的实例源码
Game.java 文件源码
项目:Lunar
阅读 31
收藏 0
点赞 0
评论 0
Game.java 文件源码
项目:KingdomKing
阅读 29
收藏 0
点赞 0
评论 0
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
}
MergedScreen.java 文件源码
项目:jvb
阅读 21
收藏 0
点赞 0
评论 0
@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();
}
CarDemo.java 文件源码
项目:AutoDrivingCarUsingNeuronNetwork
阅读 20
收藏 0
点赞 0
评论 0
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();
}
Game.java 文件源码
项目:DungeonRun2
阅读 30
收藏 0
点赞 0
评论 0
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();
}
OffscreenCanvasExample.java 文件源码
项目:PhET
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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());
}
DrawReconstruction.java 文件源码
项目:DataVec
阅读 22
收藏 0
点赞 0
评论 0
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();
}
}
Game.java 文件源码
项目:marshmallow
阅读 33
收藏 0
点赞 0
评论 0
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();
}
Game.java 文件源码
项目:OriginalSpaceShooter
阅读 28
收藏 0
点赞 0
评论 0
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();
}
Game.java 文件源码
项目:Firestorm
阅读 29
收藏 0
点赞 0
评论 0
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();
}
OffscreenCanvasExample.java 文件源码
项目:piccolo2d.java
阅读 29
收藏 0
点赞 0
评论 0
/**
* 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());
}
GameCanvas.java 文件源码
项目:JBomberman
阅读 79
收藏 0
点赞 0
评论 0
/**
* 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();
}
CanvasEngine.java 文件源码
项目:aritzh
阅读 23
收藏 0
点赞 0
评论 0
@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();
}
Game.java 文件源码
项目:StickJumper
阅读 26
收藏 0
点赞 0
评论 0
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();
}
DystopiaCanvas.java 文件源码
项目:Dystopia
阅读 26
收藏 0
点赞 0
评论 0
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();
}
ProgressUpdateFutureImpl.java 文件源码
项目:org.dayflower
阅读 23
收藏 0
点赞 0
评论 0
private void doPaint(String status, int percent) {
try {
int width = (int)(jFrame.getWidth() / 1.5D);
int height = 30;
int x = (jFrame.getWidth() - width) / 2;
int y = jFrame.getHeight() - (50 + height);
BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
Graphics graphics = bufferStrategy.getDrawGraphics();
Graphics2D graphics2D = Graphics2D.class.cast(graphics);
graphics2D.setColor(Color.BLACK);
graphics2D.fillRect(0, 0, jFrame.getWidth(), jFrame.getHeight());
doPaintBackground(graphics2D, x, y, width, height);
doPaintForeground(graphics2D, x, y, width, height, status, percent);
graphics2D.dispose();
} catch(IllegalStateException e) {
}
}
SwingGraphics.java 文件源码
项目:rabbit-escape
阅读 21
收藏 0
点赞 0
评论 0
public DrawFrame(
BufferStrategy strategy,
java.awt.Canvas canvas,
Renderer<SwingBitmap, SwingPaint> renderer,
SoundPlayer soundPlayer,
SpriteAnimator animator,
int frameNum,
World world,
WaterAnimation waterAnimation
)
{
super( strategy );
this.canvas = canvas;
this.renderer = renderer;
this.soundPlayer = soundPlayer;
this.animator = animator;
this.frameNum = frameNum;
this.world = world;
this.waterAnimation = waterAnimation;
}
Game.java 文件源码
项目:SuperSquirrel
阅读 30
收藏 0
点赞 0
评论 0
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
Graphics2D g2d = (Graphics2D) g;
/////////// Drawing begins;
g.setColor(new Color(25, 191, 224)); // background color
g.fillRect(0, 0, getWidth(), getHeight()); // Fill
for (int i = 0; i < (level.getWidth() * scale) / (tex.cloud.getWidth() / 2); i++) { // Clouds
g.drawImage(tex.cloud, (int)-cam.getX()/2 + ((tex.cloud.getWidth()/3) * i), (i % 3) * (i % 4) * 10, tex.cloud.getWidth()/2, tex.cloud.getHeight()/2, null);
}
g2d.translate(-cam.getX(), -cam.getY()); // Cam Begins
handler.render(g); // Object rendering
g2d.translate(cam.getX(), cam.getY()); // Cam Ends
hud.render(g); // Draw HUD
/////////// Drawing ends;
g.dispose();
bs.show();
}
game.java 文件源码
项目:Project--H
阅读 29
收藏 0
点赞 0
评论 0
/**render**/
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Screen.clear();
Screen.render(x, y);
for (int i = 0; i < pixels.length; i++) {
pixels[i] = Screen.pixels[i];
}
Graphics g = bs.getDrawGraphics();
g.drawImage(image,0, 0, getWidth(), getHeight(), null);
g.dispose();
bs.show();
}
DrawReconstruction.java 文件源码
项目:Canova
阅读 23
收藏 0
点赞 0
评论 0
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();
}
}
DrawReconstruction.java 文件源码
项目:deeplearning4j
阅读 24
收藏 0
点赞 0
评论 0
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();
}
}
DialogWrapperPeerImpl.java 文件源码
项目:consulo
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void dispose() {
if (isShowing()) {
hide();
}
if (myWindowListener != null) {
myWindowListener.saveSize();
removeWindowListener(myWindowListener);
myWindowListener = null;
}
DialogWrapper.cleanupWindowListeners(this);
final BufferStrategy strategy = getBufferStrategy();
if (strategy != null) {
strategy.dispose();
}
super.dispose();
removeAll();
DialogWrapper.cleanupRootPane(rootPane);
rootPane = null;
}
Game.java 文件源码
项目:spacewar-2d
阅读 26
收藏 0
点赞 0
评论 0
public void render(){
BufferStrategy bs = this.getBufferStrategy();
if(bs == null){
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
/////////////////////////////////
g.drawImage(background, 0, 0, getWidth(), getHeight(), this);
player.render(g);
bullets.render(g);
////////////////////////////////
g.dispose();
bs.show();
}
Game.java 文件源码
项目:11-Zain
阅读 28
收藏 0
点赞 0
评论 0
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
/** Increasing number could improve speed but would slow down performance **/
createBufferStrategy(3);
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();
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
g.setColor(Color.WHITE);
g.setFont(new Font("Verdana", 0, 50));
g.dispose();
bs.show();
}
LooiWindow.java 文件源码
项目:AutonomousCar
阅读 20
收藏 0
点赞 0
评论 0
private void paint()
{
BufferStrategy bs = canvas.getBufferStrategy();
if(bs == null)
{
canvas.createBufferStrategy(3);
return;
}
g = bs.getDrawGraphics();
g.clearRect(0,0,(int)getWindowWidth(),(int)getWindowHeight());
for(int i = paintActiveLooiObjects.size()-1; i > -1 ; i--)
{
paintActiveLooiObjects.get(i).setGraphics(g);
g.setColor(Color.black);//set default color here! omg it used to be yellow and I had no idea... and i was so confused y everything was YELLOW
paintActiveLooiObjects.get(i).looiPaint();
}
g.setColor(Color.black);
g.fillRect(0,0,getWindowWidth(),viewVerticalOffset);
g.fillRect(0,viewHeight+viewVerticalOffset,getWindowWidth(),getWindowHeight());
g.fillRect(0,0,viewHorizontalOffset,getWindowHeight());
g.fillRect(viewWidth+viewHorizontalOffset,0,getWindowWidth(),getWindowHeight());
bs.show();
g.dispose();
//g.finalize();//This line gives the program a TINY performance boost
}
GameCanvas.java 文件源码
项目:The-Mysterious-Mind-Of-Jack
阅读 26
收藏 0
点赞 0
评论 0
public void draw() {
requestFocus();
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = currentFrame.getGraphics();
GameCanvas.g = g;
g.setColor(Color.GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
if (Game.paused) {
if (!isBlurred) {
if (StateHandler.pausedGame != null) {
StateHandler.pausedGame.render(g);
blurred = Tools.blur(currentFrame);
isBlurred = true;
}
}
} else isBlurred = false;
StateHandler.render(g);
bs.getDrawGraphics().drawImage(currentFrame, 0, 0, StateHandler.WIDTH, StateHandler.HEIGHT, null);
g.dispose();
bs.show();
}
VSyncedBSManager.java 文件源码
项目:OpenJSharp
阅读 24
收藏 0
点赞 0
评论 0
/**
* Lets the manager know that this buffer strategy is no longer interested
* in being v-synced.
*/
public static synchronized void releaseVsync(BufferStrategy bs) {
VSyncedBSManager bsm = getInstance(false);
if (bsm != null) {
bsm.relinquishVsync(bs);
}
}
VSyncedBSManager.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
@Override
public synchronized boolean checkAllowed(BufferStrategy bs) {
if (strategy != null) {
BufferStrategy current = strategy.get();
if (current != null) {
return (current == bs);
}
}
strategy = new WeakReference<BufferStrategy>(bs);
return true;
}
VSyncedBSManager.java 文件源码
项目:OpenJSharp
阅读 24
收藏 0
点赞 0
评论 0
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
if (strategy != null) {
BufferStrategy b = strategy.get();
if (b == bs) {
strategy.clear();
strategy = null;
}
}
}
Panel.java 文件源码
项目:VTerminal
阅读 26
收藏 0
点赞 0
评论 0
/** Draws every character of every row onto the canvas. */
public void draw() {
final BufferStrategy bs = this.getBufferStrategy();
do {
do {
final Graphics2D gc;
try {
gc = (Graphics2D) bs.getDrawGraphics();
} catch (final NullPointerException | IllegalStateException e) {
// BufferStrategy may not have been created on the first call,
// so just do a recursive call until it works.
// This may be a bad idea.
draw();
return;
}
gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
gc.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
gc.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gc.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
// Font characters are pre-rendered images, so no need for AA.
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
// No-need for text rendering related options.
gc.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
gc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
// If alpha is used in the character images, we want computations related to drawing them to be fast.
gc.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
screen.draw(gc, imageCache);
gc.dispose();
} while (bs.contentsRestored()); // Repeat render if drawing buffer contents were restored.
bs.show();
} while (bs.contentsLost()); // Repeat render if drawing buffer was lost.
}