Questions tagged [pygame-clock]

This tag is for questions about clocks and timing in pygame.

The tag is related to . Timing is supported by the pygame.time module.

74 questions
22
votes
4 answers

pygame clock.tick() vs framerate in game main loop

Every pygame has a game loop that looks like this: while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.display.flip() print("tick " +…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
5
votes
2 answers

Why is my program became really laggy after I added rotation, and how do I fix this?

I'm making a game using pygame, and I have an asteroid class. When I add rotation to the update method and I run the program, the asteroids move really slow and laggy, and even their images look worse then before. I am not sure how to fix this and…
Omer
  • 223
  • 1
  • 8
5
votes
1 answer

Pygame Clock - How long can it run for?

I use Python and pygame for a control and automation task. Information from a sensor is displayed using pygame then is recorded elsewhere. To limit the framerate I am using the pygame clock tick. As this is an embedded application the process could…
4
votes
2 answers

Pygame - Is it possible to change the background image in relation to time?

I'm using pygame in order to create a sort of animation. What I have in mind is to have a series of background images change in relation to the time that has passed once I initiate the game. I came up with this code to do so: while True: …
4
votes
2 answers

Counting time in pygame

I want to count time in pygame, when an event occurs. Ive read something in the documentation but I dont really understand on how to do it. In the documentation you can get time in miliseconds but it starts counting when the pygame.init() is called.…
Jože Strožer
  • 663
  • 1
  • 6
  • 14
3
votes
1 answer

Why is my platform game in PyGame suddenly so slow?

So I have a platform game I made in PyGame that all works, so I am now trying to make it a bit more colourful. So the code that I changed used to be: def draw(self, screen): """ Draw everything on this level. """ # Draw the background …
mabski
  • 153
  • 1
  • 2
  • 11
2
votes
1 answer

Trying to change image of moving character in every 0.25 seconds PyGame

So i am trying to 'animate' my character in pygame by changing between 2 pictures when he walks. I tried to use the code that was mentioned here: In PyGame, how to move an image every 3 seconds without using the sleep function? but it didn't turn…
Einliterflasche
  • 473
  • 6
  • 18
2
votes
1 answer

Framerate affect the speed of the game

I am practicing on pygame and I was wondering how can we do so that the framerate does not affect the speed of execution of the game I would like FPS to not be locked and the game to always run at the same speed. Until now I used the…
Tangax
  • 43
  • 5
2
votes
2 answers

Lag when win.blit() background pygame

I'm having trouble with the framerate in my game. I've set it to 60 but it only goes to ~25fps. This was not an issue before displaying the background (was fine with only win.fill(WHITE)). Here is enough of the code to reproduce: import os,…
2
votes
2 answers

How to show text for 5 seconds then disappear and display buttons?

I am trying to make it so when you get an answer correct in my trivia game, it will get rid of the big question you see and say "well done" for 5 seconds and then go back to the main menu where there are 4 randomly selected questions. The questions…
2
votes
1 answer

Stopwatch between mouse up/down

I am trying to test the time between mouse down and mouse up events by using a simple stopwatch in a while loop. The mouse down event works fine, but when i release the mouse for mouse up, the seconds continue to go up and do not stop. from pygame…
WMG
  • 23
  • 2
2
votes
1 answer

Unable to properly refresh display in Pong game

import pygame, sys pygame.init() display_width = 800 display_height = 500 white = (255, 255, 255) display = pygame.display.set_mode((display_width, display_height)) pygame.display.set_caption('Pong') clock = pygame.time.Clock() platform_y =…
Kefir
  • 23
  • 3
1
vote
2 answers

Pygame clock tick stuttering

This is an issue that has been bugging me for a few weeks now. Whenever I have a pygame clock variable, so for example: clock = pygame.time.clock and I limit the fps using: clock.tick(fps) the game will occasionally stutter. I have a simple example…
1
vote
1 answer

Second surface doesn't appear on screen until I freeze the game

I'm trying out Pygame and started with a classic, creating the Snake game, the issue is that I try to blit the 'apple' on the board but the apple doesn't appear up until I crash in the walls this is when I set fps = 0 and I freeze the game. I've…
Uponn
  • 199
  • 2
  • 3
  • 15
1
vote
2 answers

Timed user input in Python

I am trying to take user input in Python with a timer. I want the user to only have 10 seconds to enter something. However when 10 seconds is over the message "Time up!" is printed but the script does not stop. import pygame from threading import…
1
2 3 4 5