本文整理汇总了Java中java.awt.Canvas.createBufferStrategy方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.createBufferStrategy方法的具体用法?Java Canvas.createBufferStrategy怎么用?Java Canvas.createBufferStrategy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Canvas
的用法示例。
在下文中一共展示了Canvas.createBufferStrategy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Window
import java.awt.Canvas; //导入方法依赖的package包/类
public Window(KTech gc) {
image = new BufferedImage(gc.getWidth(), gc.getHeight(), BufferedImage.TYPE_INT_RGB); //Passes through the width and height
canvas = new Canvas();
Dimension s = new Dimension((int)(gc.getWidth() * gc.getScale()), (int)(gc.getHeight() * gc.getScale()));
canvas.setPreferredSize(s);
canvas.setMaximumSize(s);
canvas.setPreferredSize(s);
//Setting up the JFrame
frame = new JFrame(gc.getTitle());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(canvas, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
canvas.createBufferStrategy(1);
bs = canvas.getBufferStrategy();
g = bs.getDrawGraphics();
}
示例2: start
import java.awt.Canvas; //导入方法依赖的package包/类
/**
* Starts displaying the game.
*/
public void start()
{ requestFocus();
loop.setPanel(this);
if(mode==0)
{ int width = getPreferredSize().width;
int height = getPreferredSize().height;
image = createImage(width, height);
}
else if(mode==1)
image = createVolatileImage();
else if(mode==2)
{ Canvas canvas = new Canvas();
canvas.setPreferredSize(getPreferredSize());
add(canvas);
canvas.createBufferStrategy(2);
bufferStrategy = canvas.getBufferStrategy();
}
}
示例3: create
import java.awt.Canvas; //导入方法依赖的package包/类
public static void create(int width, int height, String title, int _clearColor, int numBuffers) {
if (created)
return;
window = new JFrame(title);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
content = new Canvas();
Dimension size = new Dimension(width, height);
content.setPreferredSize(size);
window.setResizable(false);
window.getContentPane().add(content);
window.pack();
window.setLocationRelativeTo(null);
window.setVisible(true);
buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
bufferData = ((DataBufferInt) buffer.getRaster().getDataBuffer()).getData();
bufferGraphics = buffer.getGraphics();
((Graphics2D) bufferGraphics).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
clearColor = _clearColor;
content.createBufferStrategy(numBuffers);
bufferStrategy = content.getBufferStrategy();
created = true;
}