Java Game Development #4 – Starting Some Buffers

Complete Java Game Development Course now available at my website

In this video we learn how to start buffering our game and having our Graphics variable available so we can start drawing stuff onto the screen. If you have any questions then be sure to leave a comment or contact me on twitter; realtutsgml. If you learned something then be sure to leave a like, comment, and favorite.

Have you ever wanted to create games? Have you ever gotten fed up with it being to difficult? Well now is the time to thank me and possibly subscribe because you have just found the channel for you! Game Maker Tutorials, Java Game Programming, Unity3D Tutorials, Batch, C++ and much much more! This is the channel for you, the one stop shop for an exploration of your hidden talent as a game developer. Unleash your potential and go wild with imagination when you finally figure out how to make any game you want!

Visit CodingMadeSimple for more exclusive tutorials and get the help you need to succeed as your very own indie game developer!

Follow me on twitter for exclusive content and interaction with me!

Game Maker Studio: Programming
Game Maker Studio: Tutorial
Java Programming
Game Programming
Game Tutorial
Programming Tutorial






25 responses to “Java Game Development #4 – Starting Some Buffers”

  1. Laser Bean Avatar

    Mine averages 500fps. lol.

  2. dongs sanchez Avatar

    so ur saying is less bufferstrategy would make the buffer slower but makes the game load faster?

  3. Lordense Avatar

    It don't recognize image by the g.drawImage. It says I have to create an variable for it.

  4. Kamal Ahmad Avatar

    can I use this buff strategy on jpane?

  5. Eli Holst Avatar

    im getting an error. java.awt.Canvas.createBufferStrategy(Unknown Source)

  6. Xblazer 101 Avatar

    um…. the buffersrategy thing gives me an error… can someone help me pls?

  7. kindpotato Avatar

    Do you really need to create a new buffer stategy everytime you call render. Also, why would you call render so many times between updating. Seems pointless if nothing has moved.

  8. Silas Mcfarlane Avatar

    Hey +RealTutsGML When you do a private coding lesson session, does it cost money and would we use skype or something?

  9. Edward Langstrand Avatar

    Im getting orgasms from this because i have been doing things unclearly and stupid for three years… <3 Thanks alot ^^

  10. Nevin Rhymer Avatar

    my fps is around 9000 after the drop

  11. Timo Steinert Avatar

    BufferStrategy bs = new this.getBufferStrategy(); does not work.

  12. Kepler Avatar


    Exception in thread "Thread-2" java.lang.IllegalStateException: Component must have a valid peer
    at java.awt.Component$FlipBufferStrategy.createBuffers(
    at java.awt.Component$FlipBufferStrategy.<init>(
    at java.awt.Component$FlipSubRegionBufferStrategy.<init>(
    at java.awt.Component.createBufferStrategy(
    at java.awt.Canvas.createBufferStrategy(
    at java.awt.Component.createBufferStrategy(
    at java.awt.Canvas.createBufferStrategy(

  13. Notorious Avatar

    for some reason my game screen seems smaller than yours can someone help me?

  14. Darragh Walsh Avatar

    what would happen if i changed the 3 to a 12? (4:50)

  15. Fedegas Avatar

    Amazing videos, man!

    Thanks alot

  16. RestLess PvP Avatar

    If your lazy xD

    import java.awt.Canvas;
    import java.awt.Dimension;
    import java.awt.image.BufferStrategy;
    import java.awt.image.BufferedImage;

    import javax.swing.JFrame;

    public class Game extends Canvas implements Runnable {

    private static final long serialVersionUID = 1L;
    public static final int WIDTH = 320;
    public static final int HEIGHT = WIDTH / 12 * 9;
    public static final int SCALE = 2;
    public final String TITLE = "2D Space game";

    private boolean running = false;
    private Thread thread;

    private BufferedImage image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB); 

    private synchronized void start(){

    running = true;
    thread = new Thread(this);

    private synchronized void stop(){
    if (!running)

    running = false;
    try {
    } catch (InterruptedException e) {

    public void run(){
    long lastTime = System.nanoTime();
    final double amountOfTicks = 60.0;
    double  ns = 1000000000 / amountOfTicks;
    double delta = 0;
    int updates = 0;
    int frames = 0;
    long timer = System.currentTimeMillis();
    long now = System.nanoTime();
    delta += (now – lastTime) / ns;
    lastTime = now;
    if(delta >= 1){

    if(System.currentTimeMillis() – timer > 1000){
    timer += 1000;
    System.out.println(updates + " Ticks, Fps " + frames);
    updates = 0;
    frames = 0;


    private void tick(){


    private void render(){

    BufferStrategy bs = this.getBufferStrategy();


    public static void main (String args[]){
    Game game = new Game();

    game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));

    JFrame frame = new JFrame(game.TITLE);



  17. Jose Dominguez Avatar

    I got an error message on line 20. cannot find symbol
    Referring to the "BufferedImage" part. Any idea what I missed?

  18. ArcMaster Avatar

    Error: Main method not found in class, please
    define the main method as:
    public static void main(String[] args)
    or a JavaFX application class must extend javafx.application.Application

    Help Please

  19. Joe Aston Avatar

    I got around 2000 FPS after create loop, and now my FPS drop to +/- 800

  20. Nhaselton Avatar

    This code is just like DesignsbyZephyr's Tutorial. maybe you should credit him

  21. Adam Hill Avatar

    At the end the 

    g.drawImage(image, 0, 0, getWidth(), getHeight(), this);

    Don't remove it if you have bad eye sight, it will cause tons of flash and cause headaches if you look at it for too long!!! 


  22. Stackersaurus Avatar

    wierd, I don't get a black screen, pls help

  23. Elias L Avatar

    To clear the screen every frame, should i use g.clearRect or just drawImage?

  24. Sarkhamy Avatar

    For some reason it says that BufferedImage doesn't exist. I imported it: import java.awt.*. but it won't load Buffer Image or Buffer strategy.

  25. Robert Langford Avatar

    anyone's actual program screen not show? RSVP x

Leave a Reply

Your email address will not be published. Required fields are marked *