Game Development Tutorial – 13 – Time Based Animation

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






48 responses to “Game Development Tutorial – 13 – Time Based Animation”

  1. Pimpcat Forthelols Avatar

    you really only have to do clock.tick(60) for 60 Fps or clock.tick(30) for 30 Fps.

  2. Phea utube Avatar

    I  dont understand bucky, is it really necessary to put 1000. I tested it in idle, 5/2=2.5 it still showed me the answer wit decimal point. So why is the dot necessary here? thx u.

  3. AvZ NaV Avatar

    Shouldn't second be equal to millisecond * 1000?

  4. Nathan George Avatar

    i don't get how tis counts milli seconds and seconds when i tell it to print seconds it prints:  00.12
    then: 00.13
    and does that back and forth

  5. uibis Avatar

    There is a function get_fps() that can be used as well

  6. Andreas Myrup Avatar

    Why make it in the while loop and not under speed?

  7. Νίκος Μπαμπαλιάρης Avatar

    You can just import time and tell this it'w easier:

    x += 1

  8. Ryan Creasy Avatar

    the ball wont move for me unless i am moving my mouse 🙁

  9. WilliamFiset Avatar

    I have 40+ pygame tutorials on my channel for those interested

  10. Rxgamer Avatar

    my animation is much faster now…

  11. Rxgamer Avatar

    this is python….

  12. Rxgamer Avatar

    Did u just figure this out….

  13. Ryan Burmeister Avatar

    The value for clock.tick() returns a 0 for me and when it is divided, it results in a zero. Anybody know why?

  14. SkrilGamesify Avatar

    I havn't figured what .tick() does

  15. Ducksonqrack Avatar

    When I typed clock.tick(), after defining clock, into python shell it returned 10681. Anyone know what that number means?

  16. Cody Kiser Avatar

    So I found that when you dont blit a background image your animated image doesnt update and just draws the picture after every frame and never derenders it. Anyone know a reason for this?

  17. LordLiquidBaconII Avatar

    If you still need the answer, in this series we are using python.

  18. TheMrFarquad Avatar

    Can you not just do "clock.tick(x)" where x is your desired FPS?

  19. Justin Smith Avatar

    This is a very bad method. Not only is the time module slower than the pygame tick(), it also lacks the dynamic sleeping. Pygame's tick() will sleep for the amount of time needed to maintain the specified framerate. Using time.sleep() could be devastating on a slower computer, or any computer wuth different specs than yours. A faster computer would run the game faster with a static sleep time..

  20. Justin Smith Avatar

    I believe it is more pythonic to create variables to prevent newline escaping. You can also put newlines after any "(" without the use of .

  21. spj Avatar

    also i think you can use for the reverse effect, to break up long lines that would wrap around, and instead continue them in the next line to make it more readable. after all that's the the design philosophy behind python ^^

  22. TheOleYeller Avatar

    anyone else get artifacts from the ball moving left on thee screen

  23. Justin Smith Avatar

    Instead of setting a milli var I just did seconds = clock.tick()/1000.0. It's nice to keep things easily readable by writing out all the logic, but too much simplicity can have the reverse effect. The ';' operator is also nice, for preventing 5 characters from hogging an entire line. Ex. dm = seonds* speed ; x += dm. Here you create the local variable, and use it immediately, all on one line.

  24. Takatino Walrus Avatar

    But that is if you want to have a simple time delay.

  25. Takatino Walrus Avatar

    Or you can use the built in time module Example:

    import time
    print "Hello"
    time.sleep(1) #Sleep for 1 second
    print "My name is…"
    time.sleep(0.5) #Sleep for 0.5 seconds, demonstrating the fact that it can use decimals.
    print "Bob!"

  26. Matthew Franklin Avatar

    the screen variable was invalid for some reason for my ball

  27. Shrey Joshi Avatar

    just forgot to turn the int to float and every thing was chaos haha

  28. Justin Darveau Avatar

    pls have downloadable source codes so I can see what i did wrong

  29. Mc Stevens Avatar

    Great tutorial but no ball shows up on my screen when i run it… plz help?

  30. DDlol01 Avatar

    C++ looks a way different.
    if you look at 3-4 different programming/script languages (eg. Java, C/C++, python, lua) you will see the differences.
    Java has {} and other keywords, C++ also but with more operators, python needs whitespaces and lua uses the keyword "end" more often.
    For a beginner it would be nothing, but these differences are huge for compiling the stuff. Java also has another logic of programming than C (object-oriented, procedural)
    but in my opinion Python looks like C sometimes.

  31. Goldberg Nosenstein Avatar

    whatabout collision detection?

  32. Giuliano Libonati Avatar

    why the twoo top comments are the same!! lol

  33. who885 Avatar

    These tutorials are fucking addictive!

    yes/no? 😀

  34. Dancrunch10 Avatar

    Hey so i added (print milli) after milli was defined to see how it works but i don't get why the time is not constant? Sometimes i get a number in 4/5 range other times in the 1000s.

  35. Herp Derpingson Avatar

    @youagain1996 The tick() thingy forces the computer to wait 1 milisecond. the snippet you typed above doesnt allow it to tick

  36. kuan kuan Avatar

    @ncdave4life if " clock.tick() returns the number of milliseconds which have elapsed since the last time clock.tick() was called. " I wonder how many seconds will be returned for the first time it be called? Thanks!

  37. nzkozar Avatar

    @youagain1996 Because the clock.tick() line returns milliseconds passed from the previous execution of this line and this might not always be 1 millisecond. It can be 2/3/4/5/… depending on how long it takes for the loop to repeat itself on a given computer.
    So if it takes 3 milliseconds, then the ball will move 0.750 pixels instead of just 0.250 and the result will be the same as on a faster computer, where it would take only 1 millisecond to repeat the loop.

  38. Eli Edrian Tan Avatar

    why not just put in



  39. UnchainTheNight1 Avatar

    @NIN1024 It sound like you need to remove your mouse events.

  40. Jonathan Persson Avatar

    "After you blit you ball" makes me laugh every time!

  41. Alejandro Fung Avatar

    @NIN1024 pygame.display.flip() ?

  42. Maximiliano Chiesa Avatar

    These tutorials are fucking addictive!

  43. Aleksander Avatar

    i don`t can make a background.

  44. TorSkywalker Avatar

    @ben1996123 he doesn't want 1 second. He want's the time in milliseconds expressed in seconds. For example 5 milliseconds are 0.005 seconds (divided by 1000). If you multiply the 0.005 sec with the speed "250" then, you get 1,25 as distance which is exactly 250 distance per second.

  45. Rynocerous456 Avatar

    Has anyone else noticed that the pygame.time.Clock() module is really innacurate? I'm trying to get an event to line up with beats in a song but the clock gets ever so slightly off after several measures. Does anyone know how to fix this?

  46. ben1996123 Avatar

    I understand it all, apart from one thing, when you wanted to find 1 second, you divided 1 millisecond by 1000, I thought you would have to multiply the milliseconds by 1000 to get seconds…

  47. VRCkid11 Avatar

    @cheesismrulez C++ has a different syntax, but the logic of most programing languages are the same

Leave a Reply

Your email address will not be published. Required fields are marked *