Package catchemrpg.base

Source Code of catchemrpg.base.GameWindow

package catchemrpg.base;

import catchemrpg.functions.WindowCloseListener;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

/**
* The main (and only) window.
* @author Toby Pinder (Gigitrix)
*/
public class GameWindow {

    /**
     * backBuffer for graphics. This is the backBuffer, which will be drawn on
     * every frame.
     */
    public static Graphics2D backBuffer;
    /**
     * Current graphics. These are not accessed directly, but are buffered in using backBuffer
     * @see #backBuffer
     */
    public static Graphics graphics;
    /**
     * Buffered image
     */
    public static BufferedImage bi;
    /**
     * The current graphicsConfiguration
     */
    public static GraphicsConfiguration gc;
    /**
     * The current graphicsDevice
     */
    public static GraphicsDevice gd;
    /**
     * graphicsEnvironment
     */
    public static GraphicsEnvironment ge;
    /**
     * bufferStrategy
     */
    public static BufferStrategy buffer;
    /**
     * Main JFrame
     */
    private static JFrame window;
    /**
     * Drawing canvas to create game on.
     */
    public static Canvas canvas;

    /**
     * Initialise the main window, and kick off the main loop.
     */
    public void start() {
        // Create game window...
        window = new JFrame();
        window.setIgnoreRepaint(true);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setBounds(0, 0, BaseVars.WINDOWWIDTH, BaseVars.WINDOWHEIGHT);
        window.setTitle(BaseVars.lang.ui$windowTitle);
        window.requestFocus();
        window.setResizable(false);
        window.addWindowListener(new WindowCloseListener());
// Create canvas for painting...
        canvas = new Canvas();
        canvas.setIgnoreRepaint(true);
        canvas.setSize(BaseVars.WINDOWWIDTH, BaseVars.WINDOWHEIGHT);
//add listeners to the canvas, not the window.       
        canvas.addKeyListener(BaseVars.keyboardInput);
        canvas.addMouseListener(BaseVars.mouseInput);
// Add canvas to game window...
        window.add(canvas);
        window.pack();
        window.setVisible(true);
// Create BackBuffer...
        canvas.createBufferStrategy(2);
        buffer = canvas.getBufferStrategy();
// Get graphics configuration...
        ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        gd = ge.getDefaultScreenDevice();
        gc = gd.getDefaultConfiguration();
// Create off-screen drawing surface
        bi = gc.createCompatibleImage(BaseVars.WINDOWWIDTH, BaseVars.WINDOWHEIGHT);
// Objects needed for rendering...
        graphics = null;
        backBuffer = null;
        GameLoop.start();
    }
}
TOP

Related Classes of catchemrpg.base.GameWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.