当前位置: 首页>>代码示例>>Java>>正文


Java BufferStrategy.contentsLost方法代码示例

本文整理汇总了Java中java.awt.image.BufferStrategy.contentsLost方法的典型用法代码示例。如果您正苦于以下问题:Java BufferStrategy.contentsLost方法的具体用法?Java BufferStrategy.contentsLost怎么用?Java BufferStrategy.contentsLost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.BufferStrategy的用法示例。


在下文中一共展示了BufferStrategy.contentsLost方法的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: 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

示例3: 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

示例4: draw

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
/** 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.
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:41,代码来源:Panel.java

示例5: drawScene

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
@Override
public void drawScene(Snowflake[] scene, ScreenParameters screenParameters) {
    if (DEBUG_SHOW_FPS) fpsCounter.recordFrame();

    BufferStrategy strategy = getBufferStrategy();
    do {
        do {
            Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
            SnowFlake3DRenderer snowFlake3DRenderer = new AwtSnowflakeRenderer(g2d, screenParameters);

            drawBackground(g2d, screenParameters);
            for (Snowflake snowflake : scene) {
                snowFlake3DRenderer.renderSnowflake(snowflake.x + xoffset, snowflake.y, snowflake.size, snowflake.z, screenParameters);
            }

            if (DEBUG_SHOW_FPS) {
                g2d.setColor(Color.white);
                g2d.drawString(String.format("%.2f min FPS", fpsCounter.getMinFps()), 20, 20);
                g2d.drawString(String.format("%.2f max FPS", fpsCounter.getMaxFps()), 20, 35);
            }

            g2d.dispose();

        } while (strategy.contentsRestored());

        strategy.show();
        DEFAULT_TOOLKIT.sync(); // Seems like this is necessary on Ubuntu for smooth animation
    } while (strategy.contentsLost());
}
 
开发者ID:martinmarinov,项目名称:snowstorm,代码行数:30,代码来源:AwtCanvasPainter.java

示例6: drawToScreen

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private void drawToScreen() {
	final BufferStrategy bufferStrategy = canvas.getBufferStrategy();
	
	do {
		final int returnCode = validateImage(screenImage);
		
		if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
			screenImage = createImage();
		}
		
		if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE || returnCode == VolatileImage.IMAGE_RESTORED) {
			redraw();
			
			return;
		}
		
		final Graphics2D canvasGraphics = (Graphics2D)bufferStrategy.getDrawGraphics();
		
		ImageUtils.applyLowGraphics(canvasGraphics);
		
		canvasGraphics.clearRect(0, 0, canvasWidth, canvasHeight);
		canvasGraphics.drawImage(screenImage, renderX, renderY, renderWidth, renderHeight, null);
		canvasGraphics.dispose();
	} while (bufferStrategy.contentsLost());
	
	bufferStrategy.show();
}
 
开发者ID:Sogomn,项目名称:spjgl,代码行数:28,代码来源:Screen.java

示例7: updateUi

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private boolean updateUi(List<Fish> school) {
	Canvas canvas = mainWindow.getCanvas();
	BufferStrategy bufferStrategy = canvas.getBufferStrategy();
	frame = new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_RGB);
	Graphics2D graphics = (Graphics2D) frame.getGraphics();
    Graphics2D g = (Graphics2D)bufferStrategy.getDrawGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
    for (int i = 0; i < school.size(); i++) {
    	BufferedImage image = new BufferedImage(PARTICLE_SIZE, PARTICLE_SIZE, BufferedImage.TYPE_INT_RGB);
 	    Graphics imageGraphics = image.getGraphics();
 	    imageGraphics.setColor(Color.YELLOW);
 	    imageGraphics.fillOval(0, 0, PARTICLE_SIZE, PARTICLE_SIZE);
 	    
 	    // TODO get fish position
 	    double fishX = school.get(i).getPosition()[0] + search.getRANGE();
 	   double fishY = school.get(i).getPosition()[1] + search.getRANGE();
 	   
		int x = (int) ((fishX * canvas.getWidth()) / (2 * search.getRANGE()));
		int y = (int) ((fishY * canvas.getHeight()) / (2 * search.getRANGE()));
 	   	graphics.drawImage(image, x, y, null);
	}
    
    graphics.drawString(String.format("FPS: %s", this.currentFPS), 10, 10);
    g.drawImage(frame, 0, 0, null);
    g.dispose();
    
    bufferStrategy.show();
    return bufferStrategy.contentsLost();
}
 
开发者ID:gearlles,项目名称:natural-computing-fss,代码行数:31,代码来源:WindowController.java

示例8: doUpdate

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private void doUpdate() {
	BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
	
	do {
		do {
			Graphics graphics = bufferStrategy.getDrawGraphics();
			graphics.dispose();
		} while(bufferStrategy.contentsRestored());
		
		bufferStrategy.show();
	} while(bufferStrategy.contentsLost());
}
 
开发者ID:WavePropagation,项目名称:org.dayflower,代码行数:13,代码来源:ProgressUpdateFutureImpl.java

示例9: doShowContents

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private void doShowContents() {
	Window window = doGetWindow();
	
	BufferStrategy bufferStrategy = window.getBufferStrategy();
	
	if(!bufferStrategy.contentsLost()) {
		try {
			bufferStrategy.show();
		} catch(IllegalStateException e) {
			handleException(e);
		}
	}
}
 
开发者ID:WavePropagation,项目名称:org.dayflower,代码行数:14,代码来源:Java2DGame.java

示例10: update

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
public void update(){
	Window w = vc.getFullScreenWindow();
	if (w!=null){
		BufferStrategy s = w.getBufferStrategy();
		if (!s.contentsLost()){
			s.show();
		}
	}
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:10,代码来源:ScreenManager.java

示例11: update

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
public void update() {
	Window w = vc.getFullScreenWindow();
	if(w != null)
	{
		BufferStrategy s = w.getBufferStrategy();
		if(!s.contentsLost())
		{
			s.show();
		}
	}
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:12,代码来源:ScreenManager.java

示例12: update

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
public void update() {
	Window window = vc.getFullScreenWindow();
	if (window != null) {
		BufferStrategy s = window.getBufferStrategy();
		if (!s.contentsLost()) s.show();
	}
}
 
开发者ID:Dakror,项目名称:VillageDefense,代码行数:8,代码来源:ScreenManager.java

示例13: update

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
/**
    Updates the display.
*/
public void update() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
        BufferStrategy strategy = window.getBufferStrategy();
        if (!strategy.contentsLost()) {
            strategy.show();
        }
    }
    // Sync the display on some systems.
    // (on Linux, this fixes event queue problems)
    Toolkit.getDefaultToolkit().sync();
}
 
开发者ID:monicalzn,项目名称:Super-Doctor-Medical-RobotI,代码行数:16,代码来源:ScreenManager.java

示例14: doProcess

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private void doProcess() {
	long elapsedTime = System.currentTimeMillis() - currentTime;
	
	currentTime += elapsedTime;
	
	BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
	
	int width = jFrame.getWidth();
	int height = jFrame.getHeight();
	
	do {
		do {
			Graphics graphics = null;
			
			try {
				graphics = bufferStrategy.getDrawGraphics();
			} catch(IllegalStateException | NullPointerException e) {
				
			}
			
			if(graphics == null) {
				return;
			}
			
			Graphics2D graphics2D = Graphics2D.class.cast(graphics);
			
			if(Constants.isRenderingInRealtime()) {
				graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
				graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
				graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
			} else {
				graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
				graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
				graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
			}
			
			graphics2D.clearRect(0, 0, width, height);
			graphics2D.drawImage(bufferedImage, 0, 0, width, height, null);
			graphics2D.setColor(Color.WHITE);
			graphics2D.drawString("FPS " + newFPS, 20, 70);
			graphics2D.dispose();
		} while(bufferStrategy.contentsRestored());
			bufferStrategy.show();
	} while(bufferStrategy.contentsLost());
	
	Toolkit.getDefaultToolkit().sync();
	
	this.elapsedTime += elapsedTime;
	
	oldFPS++;
	
	if(this.elapsedTime >= 1000L) {
		this.elapsedTime -= 1000L;
		
		newFPS = oldFPS;
		oldFPS = 0;
	}
}
 
开发者ID:WavePropagation,项目名称:org.dayflower,代码行数:59,代码来源:JFrameDisplay.java

示例15: render

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
@Override
public void render() {
	try {
		//Calculate the time that has elapsed since the previous frame:
		long elapsedTime = System.currentTimeMillis() - currentTime;
		
		//Add the elapsed time to the current time:
		currentTime += elapsedTime;
		
		//Get the BufferStrategy from the JFrame:
		BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
		
		//Get the Graphics2D instance to draw to:
		Graphics2D graphics2D = Graphics2D.class.cast(bufferStrategy.getDrawGraphics());
		
		//Get the Camera to find Rays against:
		Camera camera = getCamera();
		
		//Get the PixelMap:
		PixelMap pixelMap = getPixelMap();
		
		//Get the Pixels from the PixelMap:
		Pixel[] pixels = pixelMap.getPixels();
		
		//Get the Scene with all Lights and Shapes:
		Scene scene = getScene();
		
		//Draw some pixels:
		doDrawPixels(camera, pixels, scene);
		
		//Get the width and height of the screen:
		int width = getWidth();
		int height = getHeight();
		
		//Clear the Graphics2D instance and draw the BufferedImage to it:
		graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
		graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
		graphics2D.clearRect(0, 0, width, height);
		graphics2D.drawImage(bufferedImage, 0, 0, width, height, null);
		
		if(isFPSRenderingEnabled()) {
			graphics2D.setColor(java.awt.Color.WHITE);
			graphics2D.drawString("FPS " + newFPS, 20, 70);
		}
		
		//Dispose of the resources used by the Graphics2D instance:
		graphics2D.dispose();
		
		if(!bufferStrategy.contentsLost()) {
			bufferStrategy.show();
		}
		
		Toolkit.getDefaultToolkit().sync();
		
		this.elapsedTime += elapsedTime;
		
		oldFPS++;
		
		if(this.elapsedTime >= 1000L) {
			this.elapsedTime -= 1000L;
			
			newFPS = oldFPS;
			oldFPS = 0;
		}
	} catch(IllegalStateException e) {
		
	}
}
 
开发者ID:WavePropagation,项目名称:org.dayflower,代码行数:70,代码来源:Java2DRenderer.java


注:本文中的java.awt.image.BufferStrategy.contentsLost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。