GML Delta-Timing (Movement & Alarms)

Discussion in 'Tutorials' started by matharoo, Dec 11, 2018.

  1. matharoo

    matharoo Udemy Instructor

    Joined:
    Jul 9, 2016
    Posts:
    821
    GM Version: GMS2
    Target Platform: ALL
    Download: https://www.dropbox.com/s/6ntwlhiqkfoqiah/delta-timing.yyz?dl=0
    Links: N/A

    Summary:
    Delta-timing is used to make sure the game doesn't actually slow down due to low FPS. This tutorial teaches you how to implement delta-timing and also use it with alarms.

    Tutorial:
     
  2. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    271
    I'm doing tests myself and last thing I want to solve is animation end with script. Without delta it was pretty easy to calculate, but with delta I found out that after setting room_speed to 99999 and use imgSpeed instead of image_speed (which is set to 0) you can hit image_number(and over) on image_index for one game frame and use it as sprite switch, but haven't tested further yet.
     
    matharoo likes this.
  3. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,044
    Thank you @matharoo, very cool.

    I do have a question though.
    In terms of unlocking room_speed, is it wise to set it to 9999 for example or is there a value that is just right?
     
    matharoo likes this.
  4. matharoo

    matharoo Udemy Instructor

    Joined:
    Jul 9, 2016
    Posts:
    821
    I don't see why you would want to set the room_speed to 9999. Perhaps it has an effect that I'm not aware of? I would just keep it as 60.
     
    The Reverend likes this.
  5. Smiechu

    Smiechu Member

    Joined:
    Jul 14, 2017
    Posts:
    622
    To make the game compatible with all possible screen refresh rates?
    But even then I find it more reasonable to set it around 200-300fps.
     
    matharoo likes this.
  6. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    271
    Room speed like that unlocks any frame limit that might be. In my tests, I have a game running around actual 1400fps.
    If your delta calculations are right then that means whatever system you run, you'll get max possible fps.
    That brings its own challenges but looks neat and smooth. It's not needed and maybe you can keep it at 120 to have max reasonable fps, dunno if displays can play it faster.

    Actually, you can have a frame limit option in-game settings for players (not to waste processing power on phantom frames), and since you have delta timing down the game will run amazing.
     
    Last edited: Dec 22, 2018
    DaMuffin and matharoo like this.
  7. The Reverend

    The Reverend Member

    Joined:
    Sep 8, 2016
    Posts:
    520
    Me too and for mobiles even at 30fps. I hate when games drain my battery in no time :)
     
    NeZvers and matharoo like this.
  8. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    271
    99999 Is for testing purposes. As I said, after handling delta timing it's easy to give the option to the player to set frame limit him/her-self.
     
    matharoo likes this.
  9. BigBrotherBear

    BigBrotherBear Member

    Joined:
    Sep 17, 2016
    Posts:
    6
    Would it be affected by screens with 120Hz if I set it to 60 fps?
     
  10. matharoo

    matharoo Udemy Instructor

    Joined:
    Jul 9, 2016
    Posts:
    821
    I think it will still be limited to 60.
     
  11. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    271
    Your screen doesn't affect room_speed.
    And it really isn't good thought to run massive room_speed, 120 is good enough if you want max FPS and you have a display that supports that.
     
  12. Waterticket

    Waterticket Member

    Joined:
    Nov 22, 2016
    Posts:
    6
    Awesome tutorial! Thank you!
     
    matharoo likes this.
  13. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    coded on 30fps.... hardcoded.. everything... on 30fps... now what's the bad part if I cannot add deltatime so simply?
     
  14. matharoo

    matharoo Udemy Instructor

    Joined:
    Jul 9, 2016
    Posts:
    821
    If you've hardcoded every movement in your game to work with 30 FPS, yeah, it will be hard and time-consuming to add delta-timing, but it's not entirely impossible or infeasible, if you're making a mobile game. If it's a PC game, I wouldn't worry about it.
     
  15. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    Ahhh, that's better; I don't think I'm smart enough to install that sdk...
    ... and my coding scares me ...
     
    matharoo likes this.
  16. matharoo

    matharoo Udemy Instructor

    Joined:
    Jul 9, 2016
    Posts:
    821
    What SDK?
     
  17. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    android for 1.4; forget it, I don't feel good enough to go there anyway. But thanks ; )
     
  18. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    271
    Well, even NES run at 60fps, I would not enjoy a game as much if it wasn't holding up to it.
    Implementing delta-timing is fairly easy until in a platformer game you want to get jumping working (evil laugh). I couldn't find tutorials on that but I figured it out eventually.
     
    matharoo likes this.
  19. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    I'm laughing but have no reasons why; it feels only alot better suddenly that my project isn't a platformer...
    I took 30fps because the only reason I've heard was "60fps will make animation more smoother"... never looked for information about it; project felt ok when running; never made a test build yet....
     
  20. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    271
    @NeonBits That smoothness IS the reason why people prefer games on 60fps. If you are not making a mobile game you have no reason why not to do it 60fps.
    For mobile games I mentioned 30fps because it will drain battery slower and heat less.
     
  21. NeonBits

    NeonBits Member

    Joined:
    Sep 22, 2017
    Posts:
    348
    Since I had no reason, I took 30fps : P
    it never came to my mind about the battery; I'm just another new GM deal customer!!!!
    Hey, now the way I see it, seems I've already prepared the ground for mobile... but the controls.... I don't think so...
     
    Last edited: Feb 22, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice