Java Programming: Let's Build a Game #1

preview_player
Показать описание

Part 1 of a series on the very basic fundamentals of Java game design. 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!

Follow me on Google+ to keep updated with all of my tutorials

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

Рекомендации по теме
Комментарии
Автор

"if you wanna go ahead and pause the video now"
son, the first 14 mins took me 3 hours

zawsrdtygbhjimokpl
Автор

Explanation of the long loop:
"lastTime", "now, " and "ns" are used to calculate "delta." amountOfTicks is the amount of tics/second, and ns is the amount of nanoseconds/tick.
When delta is calculated, you have (now-lastTime)/(ns/tick), but now and lastTime are in nanoseconds, so it has units "tick". We then add this to delta, and keep going.
Whenever delta+=1, one tick has passed, and we therefore call the command tick() [[[which is explained in the video]]], and reset delta to 0 in the while(delta>=1) loop.
the if(running) loop updates the window (by rendering again), and increases the frames with 1.
the loop writes out the FPS once per second by checking if the current time is more than 1000 milliseconds (1 second) larger than "timer" was.
IF so, we update "timer" to be 1 second later (timer+=1000;), and print the amount of frames that have passed, and set frames to 0. Since this event happens once every second, the value "frames" is the frames per second.
stop() stops the game.

frederikjrgensen
Автор

I remember the first time i watched this video 6 months ago... i hardly understood anything but now? it seems so easy to build this game.

Thanks Zack, it all started from your videos.

HasNoName
Автор

NOTE: THIS ISNT FOR BEGGINERS! HE EXPECTS YOU TO KNOW A LITTLE BIT OF JAVA

sefay
Автор

First, it is definitely on the fast side. It isn't the worst thing cause I never have to wait for you. Two, you say this is the boring stuff, but as someone who only knows up to making objects and inheritance, someone who has never touched anything relating to awt or gui, the first time that rectangular canvas popped up in the middle of my screen, I was beyond excited. Everything about this has been super fun to complete, even if I am just rewriting what I see on a screen.

eicamer
Автор

The game loop basically gets the current time, and waits for the game to "tick". The delta gets the difference between the now and lastTime variable. Of course, time always changes, so the lastTime would be the now var before it changed. BTW delta means the change in two variables of similar units. Example: 100 feet and 50 feet. the delta is 50 feet (100 - 50)

cousinsplusgaming
Автор

For anyone who doesn't get fps or flashing screen: I had the exact same problem and found the problem. make sure you add running = true inside the start() method!

kjbhappy
Автор

public void run()
{
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = / 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();
}

SuperPipboy
Автор

This is the best Java Swing Game Developement Playlist I have found.

avisinha
Автор

He said this would be the most boring, tell me why I am having fun

mrpithon
Автор

I just started watching and want to say thanks for making such a good dedicated channel to coding, amazing quality and hopefully you still upload!

zackgrey
Автор

public void run() {
long lastTime = System.nanoTime(); // get current time to the nanosecond
double amountOfTicks = 60.0; // set the number of ticks
double ns = / amountOfTicks; // this determines how many times we can devide 60 into 1e9 of nano seconds or about 1 second
double delta = 0; // change in time (delta always means a change like delta v is change in velocity)
long timer = System.currentTimeMillis(); // get current time
int frames = 0; // set frame variable
while(running){
long now = System.nanoTime(); // get current time in nonoseconds durring current loop
delta += (now - lastTime) / ns; // add the amount of change since the last loop
lastTime = now; // set lastTime to now to prepare for next loop
while(delta >= 1){
// one tick of time has passed in the game this
//ensures that we have a steady pause in our game loop
//so we don't have a game that runs way too fast
//basically we are waiting for enough time to pass so we
// have about 60 frames per one second interval determined to the nanosecond (accuracy)
// once this pause is done we render the next frame
tick();
delta--; // lower our delta back to 0 to start our next frame wait
}
if(running){
render(); // render the visuals of the game
}
frames++; // note that a frame has passed
if(System.currentTimeMillis() - timer > 1000 ){ // if one second has passed
timer+= 1000; // add a thousand to our timer for next time
System.out.println("FPS: " + frames); // print out how many frames have happend in the last second
frames = 0; // reset the frame count for the next second
}
}
stop(); // no longer running stop the thread
}


honestly this isn't heavy in math it's a pretty basic game loop.

BrettFl
Автор

*Okay, here's my explanation of the game loop:*
long lastTime = System.nanoTime();
double amountOfTicks = 60;
double ns = / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int frames = 0;
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
>= 1){



if(running)
render();
frames++;

- timer > 1000){
timer += 1000;
System.out.println("FPS: " + frames);
frames = 0;
}
}
stop();


1. Gets the time in nano seconds (nano seconds? I don't know... nano time?) long numbers contain many decimal places
2. sets the ticks per frame (Also known as the frames per second, so the game will run in 60 FPS) a double contains a whole number and some decimal places
3. ns or nano seconds, divided by amountOfTicks to see how many Seconds there have been
4.delta is the time since the game last updated
5. the current time in Milliseconds
6. frames is the number of frames per seconds you're actually getting
7. while the game is running
8. now is the number of milliseconds, this has changed from lastTime as time has passed
9. by misusing the time before by the time now, you can work out the space in-between(or the delta) devide by ns to calculate the seconds
10.  sets the lastTime to now, therefore the delta can adapt and change to the number of frames you're getting.
11. While the time between each frame is less than one tick and minus one from the delta
12. if the game is running: render images, add one to frames
13. if the gap between when the timer variable was  set and now is less than 1000 Milliseconds: Add 1000 to timer, and print the frames, then set frames to 0 so it can be calculated again.

*Please correct any and all of my mistakes*
*Feel free to ask questions*

Thegenfy
Автор

Incredible how it's been 9 years but everything still seems very relevant. I'm starting my journey from here now, hopefully in 10 years time I can look back on these videos and reminisce.

richardngo
Автор

thank you SO MUCH FOR THIS! I have absolutely zero experience working with any programs and wanted to do something for fun but have always been discouraged by how confusing it is with no experience. I was honestly stupid excited just from making the screen pop up LOL but I learned a lot about how it works just from this video alone and will watch more for sure!

reiemmeline
Автор

notice how many people quit. Tutorial 1 to tutorial 2 view diff is like 80k views!

arsenicsupersonic
Автор

Hows about an epilepsy warning there bru?

NotAnIlluminatiSpy
Автор

for those that are not using eclips. dont forget to import:

import java.awt.Color;
import java.awt.Graphics;
import

otherwise you will get an error. :P

GhostKingGeorge
Автор

8 million fps...
*looks at own console*
48 million fps...

JonBruce-BlueDev
Автор

It's really important to watch the back end first few vids twice or more to really grasp what's happening. Especially if you're new to Java.
I was completely lost the first time I watched these first few videos but as you replay them it gets clearer. Nothing mystical about it :)

charlesparoissien
join shbcf.ru