Hey, I am trying to follow this tutorial: https://www.youtube.com/watch?v=dwu4DAoac-I (or you can look on yt yourself, TheChernoProject: game programming episode 6), but perhaps I made an error along the way, since it says unreachable statement at this part:
Graphics g = bs.getDrawGraphics();
If anyone has some time to spare to enlighten me as to what I did wrong, I would very much appreciate it.
Thank you in advance!
Full code:
import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferStrategy; import javax.swing.JFrame; public class Game extends Canvas implements Runnable { private static final long serialVersionUID = 1L; public static int width = 300; public static int height = width / 16 * 9; public static int scale = 3; private Thread thread; private JFrame frame; private boolean running = false; public Game() { Dimension size = new Dimension (width * scale, height * scale); setPreferredSize(size); frame = new JFrame(); } public synchronized void start () { running = true; thread = new Thread (this,"Game"); thread.start (); } public synchronized void stop() { running = false; try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } public void run() { while (running) { update(); render(); } } public void update () { } public void render() { BufferStrategy bs = getBufferStrategy(); if (bs == null); { createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); g.dispose(); bs.show(); } public static void main (String[] args) { Game game = new Game(); game.frame.setResizable(true); game.frame.add(game); game.frame.pack(); game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); game.frame.setVisible(true); game.start(); } }