GAME LOOP - Episode #03 - Platformer Tutorial Java

Поділитися
Вставка
  • Опубліковано 24 гру 2024

КОМЕНТАРІ • 122

  • @dantevante
    @dantevante Рік тому +19

    "it counts the fps per second" - kaarin gaming
    3:25

  • @nathanmandala8465
    @nathanmandala8465 Рік тому +14

    The fact that he is making things up as he goes makes you realize he has actual knowledge and isn't copying from anywhere

  • @hamoodmogus
    @hamoodmogus Рік тому +14

    He records this past midnight. That really shows how passionate is about what he's doing.

  • @KaarinGaming
    @KaarinGaming  2 роки тому +23

    Hey all. 👋
    Hope you are doing well.
    Today we implement the gameloop into the game. We will add more to it later such as the Update portion, but it follows the same pattern. We also discuss why repaint is a bad gameloop.

  • @noahgsolomon
    @noahgsolomon 2 роки тому +18

    Dude keep making content like this and there is no way you don't blow up! I'm so honored to be able to go along this game journey with you. Ur insight is more than valuable

  • @pullup3041
    @pullup3041 2 роки тому +6

    The quality of the video, the perfect explanation and the golden joke I love it.
    I try at first to make a menu for my game in javafx the tutorial and the work was painfuli didn't even you we can easily made an interface with the basic sdk
    With you it's like a game itself thank you for the work and the dedication of this tutorial you get my abonnement of course. ⭐

    • @KaarinGaming
      @KaarinGaming  2 роки тому +1

      That's some really kind words my man! :D Thanks!

  • @Eduard-107
    @Eduard-107 8 місяців тому +2

    14:00 the number you pass in is exclusive, meaning it will never get the value of passed number. It should be 256.

  • @squeegeexd2127
    @squeegeexd2127 2 роки тому +4

    "and if you've been playing any games for the last 10 years, I'd be surprised if you've haven't heard of FPS"
    ah yes, First Person Shooters

  • @rectaalborween8471
    @rectaalborween8471 8 місяців тому +1

    Good video man! I was really confused about what you did in 10:25 since I thought the floating point number truncates into an int of 0, but I looked back at the code and realized truncation only happens AFTER the floating point calculations are complete
    😁

  • @murilodutra8569
    @murilodutra8569 6 місяців тому +1

    Aula boa meu galo veio, aula boa😎

  • @nikigrindhouse
    @nikigrindhouse Рік тому +1

    This helps me more than my university classes in Java do lol! Elämä laula!

  • @haongothaianh6431
    @haongothaianh6431 Рік тому +3

    Your tutorials are cool bro. Hope I can learn a thing or two at the end of this tutorial. Keep the good work king.

  • @barnnummer5milliard
    @barnnummer5milliard 2 роки тому +2

    Another great video! Thank you :) Perfect beatboxing, grandma should be proud!

  • @vincent_retro
    @vincent_retro 2 роки тому +2

    Nice intro :3
    Waiting for your next tutorial

  • @templeOfChrist1994
    @templeOfChrist1994 2 роки тому +3

    This will help a lot of people out, keep up the good work!

    • @KaarinGaming
      @KaarinGaming  2 роки тому +3

      Thanks man! :)

    • @templeOfChrist1994
      @templeOfChrist1994 2 роки тому

      @@KaarinGaming No problem! Is there a place online where you got started with learning Java? I know it for the most part, could use more practice though.

  • @nathanmandala8465
    @nathanmandala8465 Рік тому +3

    3:26
    fps per second
    frames per second per second
    🤣🤣🤣

  • @notsospecialised
    @notsospecialised 3 місяці тому +1

    Legend

  • @Clipaholick
    @Clipaholick 2 роки тому +2

    sick, good stuff man!!

  • @no_kurisu_allowed
    @no_kurisu_allowed Рік тому +1

    Dude, props to you for making such a great tutorial!!! Your teaching method is excellent, your voice is smooth and you introduce complex subjects so simply an ant would understand... Also the small jokes............ I feel very comfortable watching to your videos, thank youuu :D

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Wow Thanks!
      I appreciate the kind words :D

  • @8bitWatermelon
    @8bitWatermelon 2 роки тому +3

    These videos are off the hook I wish you more success in your coding vlogging career too fam. Thanks for the resource.

  • @joshualewis7209
    @joshualewis7209 Рік тому +1

    great video, super easy to follow. Its so hard to find videos where they properly explain what they are doing but dont spend ages overexplaining it. Im trying to learn java after already learining python and apparently every other tutorial goes the other way.

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Cheers mate! Best of luck on your journey :D

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 роки тому +1

    Thanks!

  • @silentdisposition
    @silentdisposition 2 роки тому +3

    These videos are amazing, keep up the great work 👍

  • @BanzukoKen
    @BanzukoKen 2 роки тому +1

    you need a much bigger following!! you are amazing!

    • @KaarinGaming
      @KaarinGaming  2 роки тому +1

      Thank you! :D

    • @BanzukoKen
      @BanzukoKen 2 роки тому +1

      @@KaarinGaming no thank you! Keep up the amazing content I'm confident your following will be very large not long from now. Great teacher, well spoken, comedy and make learning very very simplistic. Got to give the credit where it's due!

  • @ZimmoYT
    @ZimmoYT 2 роки тому +1

    Love the intro xd

  • @mamapuci
    @mamapuci 2 роки тому +1

    Thanks Bro! Amazing video!

  • @himanshuchoyal3314
    @himanshuchoyal3314 2 роки тому +1

    Amazing 🤩

  • @MP-vw5gc
    @MP-vw5gc Рік тому +1

    Good job!:)

  • @droidlycodes
    @droidlycodes 2 роки тому +1

    Can't wait to get into this further, I'm going to use this in Android Studio since my game is both platform and top down based!

  • @darontra
    @darontra 2 роки тому +5

    A small reminder nextInt(bound) returns random integer up to bound EXCLUSIVE. And considering that r,g,b components are in range [0;255] it should be random.nextInt(256);

  • @vindirect
    @vindirect 2 роки тому +1

    Awesome tutorial thanks :DDDD

  • @AlwaysEast
    @AlwaysEast Рік тому +1

    had my FPS limit declared as a static final byte. Was still getting framerates in the hundreds of thousands and thought no FPS limiter could contain my 4090... then, yeah, realised the division would require an integer.

  • @THMAIN-le8xz
    @THMAIN-le8xz 3 місяці тому +2

    My random is giving me an error after initializing it😭🙏...
    Never mind... I fucking love this channel...

  • @filipetossan5971
    @filipetossan5971 8 місяців тому +1

    i made the x direction a little bit slower so de rectangle jigles more in the window

  • @Typhooone
    @Typhooone Рік тому +4

    For some reason when i remove repaint(); from gamePanel, it doesnt give me an FPS count nor does the rectangle move around, any simple way to fix this?

    • @uhhsam
      @uhhsam 7 місяців тому +1

      A line of code was omitted from the tutorial. At 23:50 it is line 21. I had your problem and adding this line fixed it.

    • @charydoit1896
      @charydoit1896 5 місяців тому +1

      @@uhhsam thanks my friend..how i missed it...

  • @ragn594
    @ragn594 2 роки тому +5

    Is it possible for your fps counter to go above the set limit? Sometimes mine goes above the 120 limit and goes to 121 or 122. Is that normal?

    • @KaarinGaming
      @KaarinGaming  2 роки тому +4

      Yes. Atleast that one we add in ep3.
      We update our gameloop to take into account lost time when updating.
      It gets explained in ep 6 were we take the gameloop to the next level =)

    • @ragn594
      @ragn594 2 роки тому +2

      @@KaarinGaming Appreciate the response thanks :)

  • @BADOLODON
    @BADOLODON 2 роки тому +4

    I drew the rectangle as a different class with a draw method that gets a Graphics g parameter. My FPS was 300 while yours is 63000, can it be about that or did I do something else wrong horribly?

  • @mitogaming101
    @mitogaming101 Рік тому +1

    when we used the random class, other than using that class library can we use math. random? is that possible?

  • @noahgsolomon
    @noahgsolomon 2 роки тому

    u a g

  • @pouleetsonprophete4632
    @pouleetsonprophete4632 2 роки тому +2

    Amazing series!
    Would it be a valid game loop to use a Thread that sleeps for 1/FPS_SET seconds for each iteration of the while loop ? Because your code is checking for the condition of (now - lastFrame >= timePerFrame) constantly in the background. What would be the pros and/or cons of this kind of loop?

    • @KaarinGaming
      @KaarinGaming  2 роки тому +2

      Cheers man.
      Careful with thread.sleep. It tends to cause more issues than it solves. Give it a try for a while and you can see the difference :)

    • @pouleetsonprophete4632
      @pouleetsonprophete4632 2 роки тому +1

      @@KaarinGaming ok I will try it !

  • @stefanpetrovski6934
    @stefanpetrovski6934 11 місяців тому +1

    I don't know if this is a problem or not, but I think that my game is stuck at 30fps even tho it's displaying 120 through the fps counter.. I have compared your code with mine and it is the same. When I move the mouse cursor on the GameWindow it is moving the rectangle very laggy, it's like my rendering is somewhat stuck and nothing works.. Any tips or solutions?

  • @ocukor1
    @ocukor1 Рік тому +2

    how did you get 30k fps, I get like 4k? I'm on RTX 2080Ti. btw... your tutorials are the BEST I've come accross.

    • @KaarinGaming
      @KaarinGaming  Рік тому

      This game does not use the GPU as you think. All graphics calculations are done on CPU side.
      Also worth knowing is that it may not be a lack of power that keeps the fps down. It might detect this program running too fast and halters it.

    • @ocukor1
      @ocukor1 Рік тому +2

      @@KaarinGaming oh wow. thank you for the reply. I seriously didn't even expect it considering it's been posted a while ago. I appreciate that. I am enjoying your tutorials a lot, first ones that work for me without crazy errors that I can't figure out. Thank you so much for making these.

  • @hariskoktsidis2892
    @hariskoktsidis2892 Рік тому +1

    In my approach I created a Runnable task that updates the game loop and I submitted the task to a ScheduledThreadPoolExecutor. Is there any functional difference between the game loop that you created here and the one that I am using?
    Cool tutorials by the way.

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Not familiar with that one. A key reason why this is the gameloop is that it is constant and looping. If this task that you are using are being started and stopped over and over again, it could lead to lag and uneven ticks(updates).
      Threads are good, but starting and stopping them cannot guarantee a even "flow" for a lack of better words.
      But give it a try, maybe it works with a even fps and no lag. Who knows :)

  • @rafikamoulana2942
    @rafikamoulana2942 4 дні тому +1

    Hii I'm preparing sukuban game , is this tutorial helps ?

  • @JJunkWarrior
    @JJunkWarrior 2 роки тому +3

    I know this is kind of old but i hope i can get an answer for my question, whenever ive finished making the run method and the startGameLoop method, my FPS is set at 1 and isnt updating, is there a reason why this is happening? i followed through everything you did so far and i got this problem, thank you in advance!

    • @KaarinGaming
      @KaarinGaming  2 роки тому +1

      Hey!
      Hard to say without seeing the code. I would check out the github link for the code for this tutorial and compare.
      The code on github is for the last episode and might not match 100% what you got there now.
      Since you are on ep 3 I think you missed reset the fps counter or something similar.
      Good luck.

    • @JJunkWarrior
      @JJunkWarrior 2 роки тому +1

      @@KaarinGaming thank you so much! i chekced out the github and followed through the video again and found my problem, i didnt start the gameloop 😅, thank you a lot for making these videos they're easy to follow through and are very helpful

    • @zacharylahners6377
      @zacharylahners6377 Рік тому +1

      @@JJunkWarrior I had the same problem at first, I didn't see him type the "gameThread.start();" inside the StartGameLoop() method, might've been a jump cut or something

    • @Liquiddy
      @Liquiddy 8 місяців тому

      @@zacharylahners6377 thanks for this

  • @marlowe2215
    @marlowe2215 Рік тому +1

    Is there any reason the rectangle moving around the screen would still be pretty choppy by the end of the tutorial? The FPS counter shows a consistent 120 FPS but the movement of the rectangle certainly doesn't LOOK smooth at all. I'm on a Ryzen 5 5600g running Fedora 37 on the latest openjdk. (I wonder if it could be a Wayland vs X11 thing?)
    Thanks for the great tutorial series!

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Hey.
      Check out the discord for more help. Comments on youtube is not very useful in this.
      Cheers :D

  • @mercymars982
    @mercymars982 Рік тому +1

    Hi mate, my code is having some errors. I was doing the "adding visuals" and the rectangle just keeps shaking at 1 place. It doesn't move like yours (all around the map). How do I fix it?

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Hey.
      Take a look at github for code reference. Links in the description

    • @mercymars982
      @mercymars982 Рік тому

      @@KaarinGaming ok thank you sir

  • @maniad4203
    @maniad4203 2 роки тому +3

    Please teach the boss fight

  • @incarnateblizzard4874
    @incarnateblizzard4874 Рік тому

    thanks a lot for the tutorial! But for the randomized color: Wouldn't it be easier to just make the method like:
    private Color getRndColor() {
    Color color = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
    return color;
    }

    • @jonnyex
      @jonnyex Рік тому

      no, a lot more ez pz
      private Color rndColor() {
      return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255));
      }

  • @progamermaster2685
    @progamermaster2685 Рік тому +1

    for making random colors instead can we use math.random? also instead of writing while(true) can we write while(gameThread != null)?

    • @KaarinGaming
      @KaarinGaming  Рік тому

      Sure. That could work. Give it a try :)

  • @n0mi1k
    @n0mi1k 2 роки тому +1

    heyy, you did a great tutorial there, and I enjoy every second of new stuff I get to learn! But isn't it called RGB and not RBG? It's not big of a deal, but maybe a nice side information :D Keep up the great work!

    • @n0mi1k
      @n0mi1k 2 роки тому +1

      nvm u fixed it urself xD

    • @KaarinGaming
      @KaarinGaming  2 роки тому

      @@n0mi1k Cheers mate :D
      Yeah i had some tunnelvision going on there xD

  • @illyForeverEarly
    @illyForeverEarly Рік тому +2

    for some reason my program runs smoothly only when i drag my mouse. could anyone help explain?

    • @KaarinGaming
      @KaarinGaming  Рік тому +1

      Its a weird bug. I assume you might be on a linux os.
      There is a "bug" fix on the discord servern.

  • @aigerimaibatbek4810
    @aigerimaibatbek4810 Рік тому +2

    Hello, Why do i get 300-500 frames, while you get 30000-50000. And also, for me it works perfectly, when xDir, and yDir is just 1, but for you it is too fast? if change it to 0.003f, it is too slow for me:(

    • @aigerimaibatbek4810
      @aigerimaibatbek4810 Рік тому

      And also, when i added the threads part, the rectangle is not moving at all with the mouse.

    • @Amelia_-qy9nz
      @Amelia_-qy9nz Рік тому

      ​@@aigerimaibatbek4810I'm encountering the same problem as you are ;-;

  • @droidlycodes
    @droidlycodes 2 роки тому +1

    Finding a perfect game loop has been interesting I find I can get 60fps usually but it drops frames periodically.

    • @droidlycodes
      @droidlycodes 2 роки тому +1

      I'll be trying this when I get home my loop seems to be slow at times

  • @qiqioo8127
    @qiqioo8127 Рік тому +1

    EZ

  • @quexx_btw1898
    @quexx_btw1898 2 роки тому

    how is it running, even if i cannot see, where the methode "run" is being executed? I am a bit confused...

  • @MarvinIsCoding
    @MarvinIsCoding Рік тому

    I have a problem my rectangle only goes in one direction and won’t change any directions by its own

  • @stellaroasis
    @stellaroasis Місяць тому

    my box disappears as soon as it goes out of the frame and it never comes back , the way your one does like it bounces off the walls
    :( tried watching the video 2times but it still not working

  • @slndiilszneiei1547
    @slndiilszneiei1547 7 місяців тому

    I get an error when defining fps and fixing fps to 120. From where

  • @antoniosalvati-i6x
    @antoniosalvati-i6x 5 місяців тому

    26:26 Idk why I get 240 ms instead of 120 :(

  • @felipegomes2263
    @felipegomes2263 2 роки тому +1

    I had to let my xDir and yDir at 0.1f to get a similar speed, I guess that's not a problem right?

    • @KaarinGaming
      @KaarinGaming  2 роки тому +1

      Then you would have much faster fps count. Faster fps -> faster speed.
      But this code gets removed soon, it's a demonstration of gameloop =)

    • @felipegomes2263
      @felipegomes2263 2 роки тому +1

      ​@@KaarinGaming Apparently the reason why I got a different FPS and speed before was 'cause I made a mistake in the timePerFrame calculation, it's at 120 fps now. I'm moving to lesson 6 now, thanks for the reply though, I forgot to update that comment.

  • @jkrsna03
    @jkrsna03 Рік тому

    What's the meaning of xDir?

  • @n1N0v8
    @n1N0v8 2 роки тому +1

    Whenever I get rid of repaint(); i start to get 0 fps and it doesn't update whenever I move onto the real gameloop

    • @KaarinGaming
      @KaarinGaming  2 роки тому

      Take a look on github on github to compare your code to my code. It usually helps :)

  • @VMVladVMV
    @VMVladVMV Рік тому

    doesn't task manager better then treading and looping?

  • @Sanctivation
    @Sanctivation 6 місяців тому

    my fps cap is not working i followed your tutorial as you said but i am not able to do it.

    • @brett9958
      @brett9958 2 місяці тому

      I was having the same trOuble until a found @23:50 there is a jump cut!
      in the startGameLoop() => under "gameThread = new Thread(this);" => he has added "gameThread.start();"

  • @Jay-ym2ri
    @Jay-ym2ri 9 місяців тому

    idk why but my fps is fluctuating between 2 values

  • @ParasProgramming123
    @ParasProgramming123 Рік тому

    In game.java my loop is not working neither i am getting any movement with my key pressing no fps reading

    • @GamerKidsYT
      @GamerKidsYT 10 місяців тому

      he forgot to say gameThread.start(); under gameThread = new Thread(this); on line 21

  • @Kephers7
    @Kephers7 Рік тому

    Followed you. When I go to start the program after moving gamePanel.repaint() to the while loop. I get NullPointerException. Cannot invoke GamePanel.repaint() because this.gamePanel is null.
    :/ not sure what exactly that is referring to.

  • @ZAXKNER
    @ZAXKNER Рік тому

    Hi kaarin, i have troubles on the last part. For some reason even if i click it doesnt make any rectangle appear. It seems that my mouse Listener isnt working. Can you help me? i copy pasted everything from your github and yet, nothing happens.

  • @Komalsharma-ln3ir
    @Komalsharma-ln3ir 11 місяців тому

    i am getting 119,120,121,120,again 121 why this?

  • @shairis2007
    @shairis2007 3 місяці тому

    u are lucky that u r a guy.

  • @StellarHarbor
    @StellarHarbor 2 роки тому

    This episode is bad :c

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 роки тому +1

    Thanks!