Java Programming: Let's Build a Game #1

RealTutsGML · 1.8M views · 2014 · 20:29

Open on YouTube

Game programming & enginesIndie game developmentSoftware practice, open source & careerstutorialdated

Why Stack Overflow recommends it

Stack Overflow users cite it as the tutorial they were following when their game window, game loop or BufferStrategy code fails to compile or run.

Recommended by 2 people across 2 different months, 2015 to 2020.

What it is

The first episode of RealTutsGML's 'Let's Build a Game' series, a 20-minute Java tutorial on the basics of building a simple 2D game. It sets up a Canvas-based window and a fixed-timestep game loop with tick and render methods.

What people said

Recommends JudasMoses · 2015-08 · Stack Overflow · on “Private Void Tick(); Not working”

The function is not working any idea how to fix this. If it helps I am using this tutorial [this video] . public void run() { long lastTime = System.nanoTime(); double amountOfTicks = 60.0; double ns = 1000000000 / amountOfTicks; double delta = 0; long timer = System.currentTimeMillis(); int frames = 0; while (running) { long now = System.nanoTime(); delta += (now - lastTime) / ns; lastTime = now; while (delta >= 1) { tick(); delta--; } if (running) { render(); frames++; if (System.currentTimeMillis() - timer > 1000) { timer += 1000; System.out.println("FPS: " + frames); frames = 0; } } stop(); } private void tick(); { } private void render(); { BufferStrategy bs = this.getBufferStrategy(); if (b

Recommends fiendishbrokeboi · 2020-01 · Stack Overflow · on “Why does my compiler show a "no suitable constructor found for Window(int,int,String,Game)" error?”

I'm learning to build a game with this tutorial on youtube: [this video] I've went over the code a few times now and I can't seem to find a discrepancy between my code and the code used in the tutorial. I'm also getting this information in my terminal: new Window(WIDTH, HEIGHT, "Let's Build A Game!", this); ^ constructor Window.Window(GraphicsConfiguration) is not applicable (actual and formal argument lists differ in length) constructor Window.Window() is not applicable (actual and formal argument lists differ in length) constructor Window.Window(Frame) is not applicable (actual and formal argument lists differ in length) constructor Window.Window(Window) is not applicable (actual and formal arg

Cites Daniel J. Dunevant · 2015-10 · Stack Overflow · on “How to change color of a Window (Problems with Buffer Strategy )”

I have been trying to follow a simple tutorial online( [this video] ). When I try to enter the code that he enters I don't get the same results. Some things that I type end up as errors that it can't use. It happens particularly when I try to use GetBufferStrategy. I'm not quite sure what is wrong with my code. I could really use some help. Here's what I've got : package components; import java.awt.*; import java.awt.image.BufferStrategy; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.LayoutManager; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JButton; import javax.swing.JFrame; impo

Cites user4196492 · 2016-03 · Stack Overflow · on “What can I do to reduce lag from large amounts of objects in my game?”

To clarify, I know why my game is running slow. I have a lot of different objects in the current area and it has to tick and render all of those objects. I just don't know how to fix the problem without just making less objects. The answer I am looking for is more of a concept of how I can go about fixing this problem rather than just making a bunch of code for me to paste into my game. I am designing my games based off of tutorials by RealTutsGML [this video] . There where some issues I had to work around with his method of building games, but I figured them out. So every tick in my game, I have to look through all of the objects that currently exist. The more objects that exist, the longer it t

Cites Timppa · 2016-06 · Stack Overflow · on “The method is undefined for the type JFrame”

I followed this tutorial: [this video] and copy pasted everything and now I am getting an error: Error: Could not find or load main class The script is here, for Window class: package GamePackage; import java.awt.Canvas; import java.awt.Dimension; import javax.swing.JFrame; public class Window extends Canvas { private static final long serialVersionUID = 4882660542739611206L; public Window(int width, int height, String title, Game game) { JFrame frame = new JFrame(title); frame.setPreferredSide(new Dimension(width, height)); frame.setMaximumSide(new Dimension(width, height)); frame.setMinimumSide(new Dimension(width, height)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizab

Cites ATrashInTheWorld · 2016-10 · Stack Overflow · on “Beginning a game”

I started a game, but there is something wrong with it. It actually don't shows anything and neither give me an error. It just run it and do nothing else. Here are my codes: CLASS package Game; import java.awt.Canvas; import java.awt.Dimension; import javax.swing.JFrame; public class Window extends Canvas{ private static final long serialVersionUID = -2408406005333728354L; public Window(int height, int width, String title, Game game){ JFrame tit = new JFrame(title); tit.setPreferredSize(new Dimension(width, height)); tit.setMaximumSize(new Dimension(width, height)); tit.setMinimumSize(new Dimension(width, height)); tit.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //It make the game close

Cites user6762036 · 2016-12 · Stack Overflow · on “Why is my frame being set to a small window each time I run it?”

I am following this guy's video: [this video] . Also, I'm using Netbeans. Each time I run it, like when I tried using preffered size instead of set size, it still outputs a small window. public class APCSGame extends Canvas implements Runnable{ ... public final int WINWIDTH=1000,WINHEIGHT=500, SCALE=1;; JFrame frame; private BufferedImage backgroundMenu=null; public APCSGame(){ frame=new JFrame("Testing it out boiiiii"); setSize(WINWIDTH*SCALE,WINHEIGHT*SCALE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(null); frame.add(this); frame.pack(); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setVisible(true); } ... public static void main(String[] args)

Cites Snogg · 2017-12 · Stack Overflow · on “Java Thread in while-loop mystery”

I am developing a little jump and run game in Java. My game is overall based on an youtube tutorial ( [this video] ). I was creating a jump() method for the player. It works now thats cool but, I wanted that the player is moving 2 "fields" up with a velocity of 2. So I created a while loop which is asking for the height (or y-value) every-time and if it is smaller or even, then it sets velocity to 0. But for some reason I have to ask the Y value in the body of the while loop without doing anything with it in a extra thread (recognised that when it works while printing y). public static void jump(GameObject pObject) { if (pObject.getSpeedY() == 0) { int tmpY = pObject.getY(); pObject.setSpeedY(-2)

Cites KattyTheEnby · 2019-01 · Stack Overflow · on “How do I fix my JFrame not opening, the compiler gives me no errors, how do I fix it?”

thanks, I did not realize how much really was not working! Maybe the code I was using was outdated, heres where I am getting it from: " [this video] ", outdated?

Cites fiendishbrokeboi · 2020-01 · Stack Overflow · on “Why isn't my windows instance recognized within my Game.java class?”

I'm using this youtube tutorial: [this video] Here is the compiler error: Game.java:18: error: cannot find symbol new Window(WIDTH, HEIGHT, "Let's Build A Game!", this); ^ symbol: class Window location: class Game Here is my Game.java code: package com.tutorial.main; import java.awt.Graphics; import java.awt.Color; import java.awt.Canvas; import java.awt.image.BufferStrategy; public class Game extends Canvas implements Runnable { private static final long serialVersionUID = 8073316534757788976L; public static final int WIDTH = 640, HEIGHT = WIDTH/12*9; private Thread thread; private boolean running = false; public Game(){ new Window(WIDTH, HEIGHT, "Let's Build A Game!", this); } public synchroniz