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
1
vote
1 answer

Issues with pygame.time.get_ticks()

I have a game where I need an enemy to spawn after every 1350 milliseconds in a path. And the enemies only start coming after I click on the start button. Time interval code: sendEnemy = 0 def enemy_object_creation(sprite_list, health): global…
PradMaster
  • 83
  • 10
1
vote
1 answer

How can I randomly make holes in snake?

I have snake that is turning and drawing trajectory behind him but I don't know how to make holes like random pauses while he's drawing. I tried it and it's not random but problem is that it's very fast pause. It's like teleporting move. Here is my…
David d
  • 37
  • 5
1
vote
1 answer

How to create timers in pygame efficiently?

I want to spawn an enemy every (some number) seconds, say 5. I could do: start_time = pygame.time.get_ticks() if pygame.time.get_ticks() - start_time >= (some number): spawn_enemy() But there's one problem with that: when I change the FPS…
LMCuber
  • 113
  • 1
  • 11
1
vote
2 answers

I made velocity changing to make dash but want to add here some dash-lenght limit

so I made my character(player) to change its velocity faster if I press 'L shift' while pressing 'left key' or 'right key' at the same time. The problem is, I wanna make this 'dash' to stop when it reached to the limit I set. I want my character not…
1
vote
1 answer

Facing lag in pygame while using pygame.time.delay()

I'm building a Hangman game as my first Pygame project. Once the game ends, I want the screen to pause for a second and then display a result message for a few seconds, before exiting the game. I have the following function for that: def…
videzign
  • 11
  • 3
1
vote
1 answer

Why is my pygame program gradually getting slower the longer it runs?

I am making a platformer where the player changes the terrain by swapping the background color. All of the mechanics function properly, but the rate my program runs gradually gets really, excruciatingly slow and I don't know why. I've tried tidying…
Forgotten_tea
  • 75
  • 1
  • 7
1
vote
1 answer

How to freeze specific instance in pygame without affecting others

I am using pygame to develop a train simulator (using simply a rect to represent a train) I have a class train and this class has a stop function to stop trains at each station (defined by an x coordinate): def stop(self): current_time =…
1
vote
1 answer

Pygame not updating screen with pause

I was trying to use pygame to create a script that upon clicking run. The window changes the colours of the screen to blue, grey, red with one second delays between them, and then exit out of that loop and then run the game as per normal being the…
1
vote
1 answer

Pygame snake velocity too high when the fps above 15

I am having a hard time figuring the physics of speed in this snake game I made using pygame. The issue is that as soon as I set the fps to be above 15, the snake's speed increases as well. I know that this has to do with milliseconds etc which I…
Kevin
  • 364
  • 1
  • 2
  • 13
1
vote
1 answer

How can I use time to make random arrows in pygame?

Im trying to make a code in pygame that shows the arrow sprites randomly (like DDR). I had the idea to use time, but sleep pauses the whole program and i just want one arrow to be paused. I have tried to make a random list type caller, but that…
user12104401
1
vote
1 answer

Pygame suddenly lagging after adding a bit of code, but why?

I have a game I made with Pygame and I added a "small" update to where a sprite changes to another sprite for 80ms when pressing space, this makes the whole game lag (not just when pressing space but all the time). Can anyone help? :) Here is SOME…
1
vote
1 answer

Pygame game of life running slow

I've decided to create a simpler version of the Game of Life since I couldn't really work with my old one. I now have a GameOfLife class, but it is running very slow. When I click on a cell, it takes some time before it activates/deactivates, etc.…
1
vote
1 answer

Python Pygame Super Slow with Increased Window Size

Hardware: iMac with a 4.2GHz i7, 40 GB of DDR4 RAM, and a Radeon Pro 580 8192 MB -> Curiously, my updated code posted below ran at only 1.6 FPS on my iMac I started making a game in pygame that became unusably slow. I discovered that having a larger…
1
vote
1 answer

How to set a static background with pygame in python?

I am writing a demo with pygame in python, and want to draw a moving object on a static background. But I do not want to update the static background. At first I want to draw two layers, one for the static background and the other for the moving…
david
  • 842
  • 2
  • 8
  • 25
1
vote
1 answer

How to set waits for object in pygame without freezing other objects

Lets say I have class Truck. There are many instances of this class, on arrival to specific point instance should "unload" it's cargo - simply not move for N seconds, while other trucks should keep moving, unless they arrived to their unloading…
wasd
  • 1,532
  • 3
  • 28
  • 40