Creating a Scene Manager & Delta Time Variable | Coding a 2D Game Engine in Java #3

Поділитися
Вставка
  • Опубліковано 30 тра 2024
  • Join the Discord: / discord
    In this tutorial, I go over how to create a scene manager that will allow the game engine to switch between different "scenes", which are abstract objects that contain a game world. Next, we set up a delta time variable that can be used inside the scene manager, this delta time variable contains how much time has elapsed since the last frame. I then show how to use both of these concepts, by creating a transition from one scene to another by fading to black over 2 seconds.
    Github: github.com/codingminecraft/Ma...
    ---------------------------------------------------------------------
    Website: ambrosiogabe.github.io/
    Github: github.com/ambrosiogabe
    Here are some books I recommend if you want to learn about game engine development more thoroughly. I do not profit off any of these sales, these are just some books that have helped me out :)
    My Recommended Game Engine Books:
    Game Engine Architecture: www.gameenginebook.com/
    Game Physics Cookbook (Read this before the next physics book): www.amazon.com/Game-Physics-C...
    Game Physics (Ian Millington): www.amazon.com/Game-Physics-E...
    Game Programming Patterns (Free): gameprogrammingpatterns.com/
    My Recommended Beginning Game Programming Books:
    JavaScript Game Design: www.apress.com/gp/book/978143...
    Outro Music: www.bensound.com/royalty-free...

КОМЕНТАРІ • 108

  • @sharkpyro93
    @sharkpyro93 3 роки тому +44

    finally a good game engine playlist that isn't from 2008 and is ongoing, cant believe what i found, this stuff is HARD to learn by yourself

  • @dindindundun8211
    @dindindundun8211 3 роки тому +27

    These are amazing tutorials. They have to be the most relevant resources I've found so far. Where did you learn it all?

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +28

      Thanks man! I have learned all this stuff through a variety of different resources. I have some of the books that have helped me out listed in the description, and as OpenGL, I learned a lot about that through the learnopengl.com website (which is an amazing resource) and some of the Cherno's videos. Many things I learned are just from experience too, I've made a lot of game clones from scratch, and worked with Unity and Unreal for awhile, which gave me experience on things that worked right, and things that didn't work so well. Also, Casey Muratori and Jonathan Blow have amazing talks (they're kind of long, but they have some really good stuff in there), which have helped with bigger picture things in game dev :D

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

    In Java, integer division only occurs when you divide an integer by another integer. In the case of your FPS calculation, you divided an integer by a float, in which case Java automatically casts the integer to a float and returns a float from the operation. But I would still make the constant (1.0F in this case) an explicit float to make it clear to anyone reading the code later that we are indeed expecting to produce a float.

  • @csc316ta5
    @csc316ta5 3 роки тому +7

    For anyone curious, you can also apply State Pattern as well (makes it a bit easier to add more states/scenes to the list without having to change much).

    • @maerski5171
      @maerski5171 11 місяців тому

      i know that this is a 2 year old comment but im really interested with how i can implement this pattern with the scenes. can you point me to resources that i can read up for this?

  • @justashaco2497
    @justashaco2497 4 роки тому +10

    I guess that it's the best content about java game engine development! Thank you

    • @GamesWithGabe
      @GamesWithGabe  4 роки тому

      No problem, thanks for the support and awesome comment :D

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

    finished school work then had time to knock out this video 3 tonight WOO! i feel like im making so much progress.

  • @ibrahimaltay2045
    @ibrahimaltay2045 3 роки тому

    These video series is the one i was looking for ! it was imposiable to learn just by myself .Appriciate it!

  • @johnname7163
    @johnname7163 7 місяців тому +4

    I'm not sure how this happened, but I got "Infinity" several times when checking the FPS.

  • @kevinmonahan7584
    @kevinmonahan7584 3 роки тому

    Loving these tutorials. Very easy to follow along with.

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

    Dude, you have no idea how twisted I got for the changescene (newScene #) - I was fast forwarding and didn't realize it autoadded new scene when you throw in the number. god I feel stupid...
    Also, backing up everyone else here...you have no idea how valuable these tutorials are. Finding anything up to date is normally a ball ache ☺️

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

      Thanks Vex! And I know the feeling, I literally just spent like three hours trying to solve a problem with framebuffers because OpenGL docs aren't very helpful and nobody seems to have in depth tutorials on the topic haha

    • @The-Torbey
      @The-Torbey 3 роки тому

      @@GamesWithGabe framebuffer seems to be a problem in my project too. I tried using the lwjgl hello world part and added the functionality to switch to full screen while running. But as soon as it gets to fullscreen it is lagging like crazy. Had a video on my second monitor and it couldn't play the video anymore. Do you have any idea what the problem could be? I'm literally looking for days to find a solution

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      @@The-Torbey Hey torbey! This is probably because of a problem with our timer. Java's System.nanoSeconds() does not work right, and I switch it to glfwGetTime() later in the tutorial series, let me know if that fixes the lag :)

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

    Your guides are really great. I can see how you're thinking using java like your native speaking language, just like I do. That's awesome.

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

      Thanks Mykyta! And yea, it's funny how programming just becomes another way of thinking after you've done it for awhile haha

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

      @@GamesWithGabe yeah right, our brain handles all languages in nearly the same way. ^^

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

      @@GamesWithGabe especially object-oriented langs

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

    I noticed that in the Time class that you store the start time in a float when System.nanoTime() returns long.
    Although you fixed it by using one of lwjgl's functions, the real issue here isn't with System.nanoTime(), but rather with how you are storing it.
    Storing longs/doubles in floats/ints can cause issues due to data loss as longs/doubles use 8 bytes while floats/ints use 4 bytes.

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

      I know this is a year old but thanks so much! I was wondering why my FPS was capped at 60 with a 240 Hz monitor. This fixed it, and uncapped my FPS from 60.

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

    Thanks for the tutorial that is understandable and is not very old!!

  • @piCtrues
    @piCtrues 3 роки тому +4

    So far i must say, this is really great. I really like your videos a lot. You have a great voice and you sound like you enjoy the stuff you are doing.
    I am kinda new to programming and i started programming because i want to fulfill an idea i had, it's actually not about game development which is weird why i did look up your videos then.
    I thought i might as well give it a shot, and so far i am really impressed. :)
    Probably i can convert this even to my project which would be great >.>
    In comparsion to other Java guides and stuff i must say you are rocking it, your channel is really underrated.
    I hope you will keep going and have a beautiful day :3

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      Hey piCtrues, thank you so much for this comment! I'm glad that my videos are helping you out, and hopefully you'll be able to use some of the concepts for you're project. These comments are always a huge encouragement :)

  • @hiderr6805
    @hiderr6805 3 роки тому

    Hello! That video really helps... Thank you so much and please keep up with such an awesome content! 😊

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      No problem @Hiderr! And I don't plan on stopping anytime soon :D

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

    4:29 you are wrong. Static variables are initialized at class loading time which happens when the application interacts with one of it's methods or constructors.

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

    kind explanation that is hard to find on youtube

  • @aryaveertewari1484
    @aryaveertewari1484 3 роки тому

    Hey great video I was motivated to start developing my engine again, I had a question regarding he use of the abstract class scene here. What is it being used for.
    Thanks.

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

    I tried using double for DeltaTime instead of float and it worked better

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

    whats that book on your desk at 0:46 ?

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

    I doubt you'll read this, but I have this weird problem where my FPS show as 29.xxxxx and "infinity", then 29.x, then infinity and so on. Does anyone know what this could be?

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

      If you're seeing infinity FPS and you're early on in the game engine series, this is likely due to truncation in the `Time.getTime` function. This can be solved by replacing any calls to `Time.getTime()` with `glfwGetTime()` :)

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

      ​@@GamesWithGabe thank you so much

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

    Hello,
    When I put down your code"
    float beginTime = Time.getTime();
    float endTime;
    float dt = -1.0f;
    endTime = Time.getTime();
    float dt = endTime - beginTime;
    beginTime = endTime;"
    I get these messages:
    Non-static method 'getTime()' cannot be referenced from a static context
    Non-static method 'getTime()' cannot be referenced from a static context
    Variable 'dt' is already defined in the scope
    I followed everything you did to the letter up until that point ^^

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

    Is there a reason why we're using floats instead of doubles?

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

    My window runs but I get a quick flash of black and then into white screen even though it has successfully changed from scene 1 to the next. I checked for what I missed, but it seems that I followed correctly. Any idea what I'm doing wrong? Thanks

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

      Hey Urijah, it's probably the delta time variable that's messed up. Java's builtin System.nanoTime() did not work the way I expected so you should be able to switch that to glfwGetTime() and fix your issue

  • @alexandruantoci2691
    @alexandruantoci2691 3 роки тому +1

    I LOVE YOU

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

    Luckily today, I just installed the same IntelliJ Idea version you are using because I knew later versions wouldn't have accurate runtime.

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

    Nothing understood very good tutorial

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

    thank you

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

    In the Time class why getTime() method returned return (float) ((System.nanoTime() - Time.timeStarted)*1E-9) cant we just
    return (float)(System.nanoTime()*1E-9)

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

    everything works for me but it doesn't fade to black i9 have no errors

  • @formyeve
    @formyeve 3 роки тому +1

    What's the difference between level scene and level editor scene?

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      Level Scene is supposed to be when the game is being played, and Level Editor Scene is the scene where you're editing the levels. I change this concept in the future though and just make a Scene class that loads in different files that represent whatever you're working on

  • @charlesmctavish5188
    @charlesmctavish5188 3 роки тому

    Whenever I close the window that pops up i get the error.
    Execution failed for task ':Main.main()'.
    > Process 'command 'F:/Program Files/Java/jdk-14.0.2/bin/java.exe'' finished with non-zero exit value 1
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insight

    • @charlesmctavish5188
      @charlesmctavish5188 3 роки тому

      It works fine but i noticed when you click the red x it does not do that. I was wondering why it would throw this

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      @@charlesmctavish5188 hey Charles, I'm not sure I completely understand the problem. It definitely shouldn't be throwing that error when you close the window, and if it is I would suggest stepping through the code after the game loop to see what might be causing it :)

    • @charlesmctavish5188
      @charlesmctavish5188 3 роки тому

      @@GamesWithGabe I found it thanks. I clicked tab to early when I called destroyWindow and it accidentally auto filled destroyCursor

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

    You're SOOOOO smart, how do you know where to get all of this stuff.

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

    just want to say something funny when i print the fps it switch's between 14 and Infinity

  • @notenough595
    @notenough595 3 роки тому

    is there a way of rendering at different FPS as games do??

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      There is a way of rendering at different FPS, I would recommend staying within the V-blank which is basically the vertical blank, or the refresh rate of the monitor. I'm pretty sure that if you change the glfwSwapInterval(1) to a 2, it will be 2 v-blanks or half as fast, and if you set it to 0, it will be unlimited FPS. If you want some more information on how changing the FPS can effect the experience for different monitors I can try and link some articles and videos I've seen in the past

    • @notenough595
      @notenough595 3 роки тому

      @@GamesWithGabe thnx man...it will be great

  • @ratsec1756
    @ratsec1756 3 роки тому

    it all works till I close the window, I get a error:
    Execution failed for task ':Main.main()'.
    > Process 'command 'C:/Program Files/Java/jdk-15.0.1/bin/java.exe'' finished with non-zero exit value 1
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    :
    I have no idea why this is happening and how to fix it, if I could get some insight on this it would be great! thanks!
    Edit: I moved my project out of grade, since lwjgl has a jar version of their library, so I just used that. then I got another error were you were trying to free the error callback, but why would you free it when it is already null, it makes no sense, it caused me errors so I removed that line, but I need to know how to check if its free or not, preferably in an if statement, if true *then* clear the callback, else, just dont. dunno how though, hope you can help! :D

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      Hey TheftSec! It could be doing that for a lot of different reasons, do you know how to launch intellij, or whatever editor you're using, in debug mode? If you do I would suggest doing that and setting a break point right before the end of your code to try and see where it might be failing. Let me know if you need more info!

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

    Is it normal go get "Infinity" FPS?

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

      I'm getting that too lol

  • @Smile-ih5xf
    @Smile-ih5xf 10 місяців тому +1

    Alright I just looked 2 hours to find my mistake and than saw I tiped public void instead of only public 😂

  • @diegorodriguesmota7945
    @diegorodriguesmota7945 3 роки тому

    The tutorial is good, but you can improve the good practices in Java, like use class instead of basic types and create more specialized code.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      Hey Diego thanks for the comment! Can you expand a little more on what you mean? If you have any good articles I could check out too that would be great. I'm always interested in new development practices so long as they KISS and DRY :)

    • @diegorodriguesmota7945
      @diegorodriguesmota7945 3 роки тому

      Hey. I'm talking about simple things that make a great difference. Java is an Object Oriented Language, so, is always better use Objects instead of simple values, like Integer and Double, not int and float. So with that you can really use the benefits of the POO.
      Besides that, there are some important concepts in software quality, like Single Responsibility, that says a class must have a unique attribution. That is, if you do a class that start up the game, it must do just that, noghint else.
      Maybe read about SOLID and Clean Code can be useful.
      English is not my first language, so I hope I wasn't rude.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      @@diegorodriguesmota7945 no worries, you didn't sound rude to me at all (and you're english is really good). So, I had a feeling this is what you were alluding to, and I have shifted over the past year of developing to more of a functional style of programming. I also have some pretty strong feelings towards SOLID and clean code after working in a corporate industry where it's taken to ridiculous extremes, I have all these thoughts laid out a bit more succinctly in this video if you want to check it out ua-cam.com/video/zwcqbBB7Ei8/v-deo.html . I try to be as objective as possible, and list the downfalls that I think are created from programming in this style, and there are a lot of great articles in the link with other peoples opinions on this matter.
      So, in short I kind of just code to solve a problem and try not to let any paradigms or methodologies get in the way. And sometimes I need to refactor because it becomes a mess, but that usually only takes a couple hours and isn't too bad :)

    • @diegorodriguesmota7945
      @diegorodriguesmota7945 3 роки тому

      ​@@GamesWithGabe I think it is very important to program thinking about the maintainability and ease of expanding the code. But I understand and respect your style.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      @@diegorodriguesmota7945 thanks Diego! And I do feel the same way, programmers have different styles and if it works, it works :)

  • @dotSp0T
    @dotSp0T 3 роки тому +1

    You get nanosecond-resolution, but not necessarily nanosecond-precision. On the average system your clock won't be more precise than System.currentTimeMillis() ....

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +3

      Hey @dotSpo0T you're absolutely correct. I actually go about correcting this in a future video by swapping it out with glfwGetTime(), because it ends up causing some problems :)

    • @dotSp0T
      @dotSp0T 3 роки тому +1

      @@GamesWithGabe haha i was just about to mention the glfw function when i saw your reply. Great series otherwise, really does wonders helping me to get back to speed again!!

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

    18:10 I keep getting "InfinityFPS" xD

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

    Also for some reason mine is runnin at 30FPS even though based on my monitor's refresh rate and V-Sync on it should be 60.

    • @celinedrules
      @celinedrules 9 місяців тому

      I had this problem too. I solved it by replacing any calls to Time.getTime() with glfwGetTime()

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

    I have a question regarding the scene swapper... I tried to understand what I did wrong but it just doesn't wanna get in my head, I'd very glad if someone could help me out... the problem is that when i press the space key my scene does not smoothly change, istead it changes multiple times a second and ouputs a mix between the two colours... (in my case green and yellow)... This is because it's changings scenes that often but i don't know any way of getting the program to not do that... As I said: I'm glad for every answer regarding my question :)

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

      Hey John, this could be multiple reasons. I have to fix the timestep in a later episode by switching the System.getTimeNanoSeconds() or something like that with glfwGetTime(). The previous function makes the framerate very slow which could make it look like the colors are changing suddenly. The only other thing I can think of is that maybe you're pressing the space key and it's changing the scene multiple times because it is seeing that you're pressing the space key every frame. Without seeing your code it's kind of difficult to tell which problem it might be, but I'm betting it's probably the deltaTime variable :)

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

      @@GamesWithGabe First of all, thx for your quick and detailed answer... Actually I've also thought about the problem that it might be that my keyboard sends a few presses to my pc and that was a problem indeed but after some trial and error I found a solution to this, but my Scenes still don't wanna fade smoothly... And regarding the glfwGetTime(): It might be a great idea performancewise but I've read that it's not exact and also changes it's speed...

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

      @@johnjentges3265 Awesome! I'm glad that you thought about the multiple presses per frame, and I wouldn't worry about glfwGetTime() being inaccurate. I'm not sure where you heard that from, but it uses highest-resolution monotonic time source on whichever system is using it.
      Actually, it looks like Java's System.nanoTime() might actually be more inaccurate because it doesn't necessarily relate to the CPU's actual clock times. The docs say that it has nano-second precision, but not necessarily nano-second resolution meaning that it doesn't actually measure elapsed time every few nanoseconds. The Java docs are here: docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime() and the glfwGetTime() docs are here: www.glfw.org/docs/3.0/group__time.html#gaa6cf4e7a77158a3b8fd00328b1720a4a

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

      @@GamesWithGabe Again: Thx for the fast and deatiled reply. But actually i made aworkaound for my keyboard sending multiple presses, but it's still not fading. I would be very thankful for help... I confounded resolution and precision, I thought, that it measure like every x-th CPU clock-cycle or so...

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

      @@johnjentges3265 at this point it would probably be easiest for me to help out if you had a link to your code :). I'm not sure what the problem could be other than glfwGetTime(), but it's possible that it's in an entirely different place in the code

  • @DivyanshuLohani
    @DivyanshuLohani 3 роки тому

    Nice video but when the scene should fade it just suddenly changes to black help

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому

      That's probably because System.nanotime() doesn't seem to work properly. I eventually switch to using glfwGetTime(), and that will fix your delta time which should make it fade to black over time instead of instantly

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

      @@GamesWithGabe for some reason, this still isnt working for me

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

      @@ItsAnnabelleDoe hey Annabelle, are you having trouble with your frame rate? If you're getting really low frame rate it is most likely because of System.nanoTime(), but if you changed that to glfwGetTime() and you're still getting a problem it has to be something else. Let me know what problem you're getting and I'll see if I can give you some more help :)

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

      @@GamesWithGabe Hi, yes I managed to fix this! Thank you for the videos they’re super helpful!

  • @lenadesp7810
    @lenadesp7810 3 роки тому

    My laptop is over 90° thats good 😅😅?

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

    Java gave me "infinity" FPS at the end 0_0 lol

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

    For those having issues with the deltaTime and infinity, it has to do with the tutorial casting nanoTime to a float. Use double instead and you should be good.

    • @celinedrules
      @celinedrules 9 місяців тому

      I solved it by replacing any calls to Time.getTime() with glfwGetTime()

  • @NikitaKolosov
    @NikitaKolosov 3 роки тому +1

    Why I get just 7 fps every time? (o_O )
    Cannot say that my computer is weak

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      Hey N K, this could be a variety of problems. If you post your source code to GitHub I can take a look. But some things that immediately come to mind are to make sure your vblank is set to 1. So check to make sure the function glfwSwapInterval(1). If you list it higher then one than I believe that might artificially increase the frames. Also, there was a problem with Java's nano time that I fix in the future, it could be that it's just misreporting the speed of your application

    • @NikitaKolosov
      @NikitaKolosov 3 роки тому

      @@GamesWithGabe thanks, Gabe. I think that I catch second problem you mentioned. I think there is no sence to post whole code because even this little example shows the problem.
      public static void main(String[] args) {
      float beginTime = System.nanoTime();
      float endTime;
      float dt = -1.0f;
      while (true) {
      endTime = System.nanoTime();
      dt = endTime - beginTime;
      beginTime = endTime;
      System.out.println(dt);
      }
      }
      This peace of code print mostlty zeros, and sometimes 2.68435456E8 (about 4 times per second). Actually first time I formulated problem incorrectly. I have proper real game fps but wrong value of dt.

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      @@NikitaKolosov Yep you are correct. If you want a quick fix look into glfwGetTime() instead of Java's System.nanoTime();

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

    Huh, my FPS is a scientific notation (with an E) that has a negative exponent... I guess that's why I don't have that cool 2-sec transfer, HOW DID THIS HAPPEN? I asked my self.

  • @chameleonchamlee2551
    @chameleonchamlee2551 3 роки тому

    what t hell dude? your code throwded me infinity fps, whats wrong , ive never seen float value as infinity , also my white-black transition lasted for about 0.2 second :(

    • @chameleonchamlee2551
      @chameleonchamlee2551 3 роки тому +1

      oh I fixed it using your advice to use glfw.GetTime() while casting it to float, thx you very much

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

      @@chameleonchamlee2551 No problem! I'm glad you were able to find the comment, it's hard to put in these sort of updates into old videos :)

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

    So, if i'm not wrong : All the stuff about delta time is just for showing FPS the game run at, right ?

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

    12:35 Input ? This is isnt unity 😂

  • @Jordan4Ibanez
    @Jordan4Ibanez 3 роки тому +1

    Hey man, I'm not sure if you show this in a further video but I simplified dt into it's own class!
    package util;
    public class Time {
    private static float timeStarted = System.nanoTime();
    private static float beginTime = Time.getTime();
    private static float endTime = Time.getTime();
    public static float getTime() {
    return (float)((System.nanoTime() - timeStarted) * 1E-9);
    }
    public static float getDt(){
    endTime = Time.getTime();
    float dt = endTime - beginTime;
    beginTime = endTime;

    return dt;
    };
    }

    • @GamesWithGabe
      @GamesWithGabe  3 роки тому +1

      Nice! I actually end up getting rid of the Time class though, because there seems to be a problem with System.nanoTime(), but your code looks good :)

    • @Jordan4Ibanez
      @Jordan4Ibanez 3 роки тому +1

      @@GamesWithGabe Oooof hahaha I'm going to research on how to do dtime in a java game then!

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

    I got something like this as FPS:
    5.9604645E-8FPS
    And I have done exactly what you did.^^ Just one thing I have done different, I have updated the versions of some elements as suggested by the build.gradle.
    I know this is float spelling, but how can I get rid of that E and see some normal numbers? ^^ 😉😉