Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 834327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:39:19+00:00 2026-05-15T04:39:19+00:00

I’m working on a Tetris-clone type game and I’m wondering what would be the

  • 0

I’m working on a Tetris-clone type game and I’m wondering what would be the best way to handle the logic that moves the blocks down every N seconds. I initially did it the easy way:

pygame.time.set_timer(USEREVENT+1, 300)

This will of course add a PyGame event to the queue every 300 milliseconds. In the main loop I can test for this event, and drop the block down when it occurs. The problem with this approach is that the player can easily flood the queue with keyboard generated events. I noticed that player can essentially keep the block at the same height indefinitely by simply rapidly pressing the up-arrow which flips it around. It doesn’t seem to matter that the code testing for timer event is evaluated before the test for keyboard events. Somehow keyboard always gets higher priority than the timer. Any idea how to prevent this from happening?

And if this is unavoidable quirk of pygame.time what would be a better way to handle the timed events?

  • Check elapsed time on each loop iteration and advance blocks if it is greater than a certain value?
  • Use sched or something similar running in a separate thread and signaling back via some shared resource?

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:39:20+00:00Added an answer on May 15, 2026 at 4:39 am

    Here’s how a typical game loop works:

    repeat forever:
        read all pending events
        if current time > last frame + frame time:
            last frame = last frame + frame time
            update game
        redraw screen
    

    A timer that is supposed to fire every 300 ms but doesn’t work if the user floods the game with events could be a broken timer. However, if you redraw the screen on every user event instead of redrawing the screen once you’ve processed all pending events, then your code is the problem.

    Here’s an example of a broken version of a game loop:

    repeat forever:
        read the next pending event
        if current time > last frame + frame time:
            last frame = last frame + frame time
            update game
        redraw screen
    

    It’s broken because it tries to redraw the screen far too often. If the player presses two keys at the same time, they’ll get separated into different frames, which is unnecessary.

    The above loops assume that you want to draw to the screen as often as possible. This is very common, but you might want to draw to the screen less often. Your method of using events should be fine as long as you grab all pending events before redrawing the screen.

    P.S. Do NOT use multiple threads to solve this problem. That would cause a huge mess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.