Java Game Programming #2 - Game Loop

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

In this video we learn how to add the gameloop into our java game. 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 fun learning!

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

Believe it or not, its nearly the same loop that notch uses. I was snooping around in a few sources of his.

syszee
Автор

It was smart of you to copy down the game loop and paste it down every time u need it. Haven't thought of that until now! :D

fahdv
Автор

Why do you check if there's a buffering strategy within the render method instead of in the start method? Wouldn't it be more efficient to check during the start method?

tammyton
Автор

here is the game loop's code
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int updates = 0;
int frames = 0;
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1){
tick();
updates++;
delta--;
}
render();
frames++;

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

gordonhordon
Автор

Hey at 3:40, you said that this.getBufferStrategy() was referring to the class Canvas. However, I thought the syntax super.getBufferStrategy() accesses the Canvas class also. What is the difference?

justoaktree
Автор

2024 and still finding this helpful... thanks bro : )

XeroXipher
Автор

My code is the exact same as yours, yet it doesn't show the FPS on the console, and i dont get the black screen from buffering.

jordancreutz
Автор

Could it be possible to do all of this with notepad instead of eclipse

colbymaulden
Автор

Sometimes i roll around my carpet thinking i'll have electric powers

dr.schmeat
Автор

Pretty sure thechernoproject on youtube should be credited for this, since it belongs to him.

Woodiniii
Автор

I have executed same code as u shown
But I am not getting any output
Not showing me any FPS output
Help me out of this !!!

ChandraKishore
Автор

I have excactly the same code as you in the game class and it starts but the threads aren't working. Please help!

OfficialGamingNetwork
Автор

Is mugging up the game loop alright without understanding it? I mean if we don't understand it, then would we be able to understand the rest of the stuff ?

arjavgarg
Автор

Pretty sure you should ask thecherno where he got his code in the first place. Garunteed he did not think that up himself. If so then it looks like a ton of people copied him including notch the creator of minecraft. Do some research before commenting.

RealTutsGML
Автор

Did you come up with game loop method you use because who ever did is a genius, for me it works 99.9% of the time.

Funske
Автор

is there a difference between using your game loop cope vs the Timer you used in the beginners tuts?

hellojun
Автор

Very solid Java series! Continue with your great work! :)

ChristofferBrandsborg
Автор

i have a ( introduction to java programming ) book ok..
my question is, when u say i must know basic java what chapters in the book should i cover exactly or in other word what do you mean by basic java and are (awt, swing, thread and graphics classes consider a  basic java )????

barax
Автор

Hi I have watched the video 4 times now, I 99.9% sure my code is the exact same as yours but there is no flashing black from the buffer. Could that have something to do with the performance of my laptop or is it purely a mistake in the code? Any advice would be greatly appreciated.. Loving the tutorials.

ilovetheDough
Автор

delta and lasttime are underlined with a blue curly thingy did i do something wrong

pluisjedelft
join shbcf.ru