GAME LOOP - Episode #03 - Platformer Tutorial Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 119

  • @nathanmandala8465
    @nathanmandala8465 ปีที่แล้ว +12

    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 ปีที่แล้ว +13

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

  • @_j4yyy
    @_j4yyy ปีที่แล้ว +17

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

  • @KaarinGaming
    @KaarinGaming  2 ปีที่แล้ว +21

    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 ปีที่แล้ว +17

    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!

  • @rectaalborween8471
    @rectaalborween8471 7 หลายเดือนก่อน +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
    😁

  • @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.

  • @notsospecialised
    @notsospecialised 2 หลายเดือนก่อน +1

    Legend

  • @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.

  • @nikigrindhouse
    @nikigrindhouse ปีที่แล้ว +1

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

  • @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

  • @silentdisposition
    @silentdisposition 2 ปีที่แล้ว +3

    These videos are amazing, keep up the great work 👍

  • @barnnummer5milliard
    @barnnummer5milliard 2 ปีที่แล้ว +2

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

  • @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.

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว +1

    Thanks!

  • @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

  • @vincent_retro
    @vincent_retro 2 ปีที่แล้ว +2

    Nice intro :3
    Waiting for your next tutorial

  • @Eduard-107
    @Eduard-107 7 หลายเดือนก่อน +2

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

  • @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!

  • @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

  • @murilodutra8569
    @murilodutra8569 5 หลายเดือนก่อน +1

    Aula boa meu galo veio, aula boa😎

  • @Clipaholick
    @Clipaholick 2 ปีที่แล้ว +2

    sick, good stuff man!!

  • @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);

  • @mamapuci
    @mamapuci 2 ปีที่แล้ว +1

    Thanks Bro! Amazing video!

  • @BanzukoKen
    @BanzukoKen ปีที่แล้ว +1

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

    • @KaarinGaming
      @KaarinGaming  ปีที่แล้ว +1

      Thank you! :D

    • @BanzukoKen
      @BanzukoKen ปีที่แล้ว +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!

  • @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.

  • @himanshuchoyal3314
    @himanshuchoyal3314 2 ปีที่แล้ว +1

    Amazing 🤩

  • @ZimmoYT
    @ZimmoYT 2 ปีที่แล้ว +1

    Love the intro xd

  • @THMAIN-le8xz
    @THMAIN-le8xz 2 หลายเดือนก่อน +2

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

  • @nathanmandala8465
    @nathanmandala8465 ปีที่แล้ว +3

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

  • @vindirect
    @vindirect 2 ปีที่แล้ว +1

    Awesome tutorial thanks :DDDD

  • @MP-vw5gc
    @MP-vw5gc ปีที่แล้ว +1

    Good job!:)

  • @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 6 หลายเดือนก่อน +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 4 หลายเดือนก่อน +1

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

  • @mitogaming101
    @mitogaming101 ปีที่แล้ว +1

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

  • @filipetossan5971
    @filipetossan5971 7 หลายเดือนก่อน +1

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

  • @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?

  • @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 :)

  • @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 !

  • @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 :)

  • @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

  • @illyForeverEarly
    @illyForeverEarly ปีที่แล้ว +1

    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.

  • @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

  • @stellaroasis
    @stellaroasis 9 วันที่ผ่านมา

    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

  • @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.

  • @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 7 หลายเดือนก่อน

      @@zacharylahners6377 thanks for this

  • @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));
      }

  • @maniad4203
    @maniad4203 2 ปีที่แล้ว +3

    Please teach the boss fight

  • @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 :)

  • @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

  • @noahgsolomon
    @noahgsolomon 2 ปีที่แล้ว

    u a g

  • @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 ;-;

  • @MarvinIsCoding
    @MarvinIsCoding 11 หลายเดือนก่อน

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

  • @quexx_btw1898
    @quexx_btw1898 ปีที่แล้ว

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

  • @slndiilszneiei1547
    @slndiilszneiei1547 6 หลายเดือนก่อน

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

  • @qiqioo8127
    @qiqioo8127 ปีที่แล้ว +1

    EZ

  • @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

  • @stefanpetrovski6934
    @stefanpetrovski6934 10 หลายเดือนก่อน

    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?

  • @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 :)

  • @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?

  • @VMVladVMV
    @VMVladVMV ปีที่แล้ว

    doesn't task manager better then treading and looping?

  • @Jay-ym2ri
    @Jay-ym2ri 9 หลายเดือนก่อน

    idk why but my fps is fluctuating between 2 values

  • @antoniosalvati-i6x
    @antoniosalvati-i6x 4 หลายเดือนก่อน

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

  • @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 9 หลายเดือนก่อน

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

  • @Sanctivation
    @Sanctivation 5 หลายเดือนก่อน

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

    • @brett9958
      @brett9958 หลายเดือนก่อน

      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();"

  • @Komalsharma-ln3ir
    @Komalsharma-ln3ir 10 หลายเดือนก่อน

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

  • @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.

  • @shairis2007
    @shairis2007 2 หลายเดือนก่อน

    u are lucky that u r a guy.

  • @StellarHarbor
    @StellarHarbor 2 ปีที่แล้ว

    This episode is bad :c

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว +1

    Thanks!