pygame-clock

Stopwatch between mouse up/down

浪子不回头ぞ 提交于 2021-02-15 06:51:28
问题 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 import * import time screen = display.set_mode((160, 90)) sec = 0 while True: new_event = event.poll() if new_event.type == MOUSEBUTTONDOWN: while True: # Basic stopwatch started time.sleep(1) sec += 1 print(sec) # In loop, when mouse button

Stopwatch between mouse up/down

可紊 提交于 2021-02-15 06:51:11
问题 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 import * import time screen = display.set_mode((160, 90)) sec = 0 while True: new_event = event.poll() if new_event.type == MOUSEBUTTONDOWN: while True: # Basic stopwatch started time.sleep(1) sec += 1 print(sec) # In loop, when mouse button

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

故事扮演 提交于 2021-02-10 18:55:07
问题 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 points. I do the stop part by setting movement vector to (0,0) and then resetting it back to original. But how to wait N seconds without freezing other cars? From what I've found so far I think I need to somehow apply pygame.time.set_timer , but it is

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

空扰寡人 提交于 2021-02-10 18:52:06
问题 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 points. I do the stop part by setting movement vector to (0,0) and then resetting it back to original. But how to wait N seconds without freezing other cars? From what I've found so far I think I need to somehow apply pygame.time.set_timer , but it is

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

余生长醉 提交于 2021-02-05 07:33:12
问题 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 out too well. In fact my character only uses one image when walking. here the part of the code and some variables: self.xchange: change on x axis self.img: image for when the character stands still self.walk1 and self.walk2: the two images i am

Lag when win.blit() background pygame

旧巷老猫 提交于 2021-01-29 22:13:20
问题 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, pygame os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (50, 50) pygame.init() bg = pygame.image.load('images/bg.jpg') FPS = pygame.time.Clock() fps = 60 WHITE = (255, 255, 255) BLUE = (0, 0, 255) winW = 1227 winH = 700 win = pygame.display.set_mode((winW,

How can I randomly make holes in snake? [duplicate]

一个人想着一个人 提交于 2021-01-05 07:39:14
问题 This question already has answers here : how to handle time for different components in pygame (1 answer) How to run multiple while loops at a time in Python [duplicate] (1 answer) Pygame clock and event loops (1 answer) Closed 17 days ago . 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 code:

Framerate affect the speed of the game

自古美人都是妖i 提交于 2020-12-18 05:00:10
问题 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 pygame.time.Clock.tick function but the speed of the character was changing depending on the number of FPS, which I don't want. 回答1: pygame.time.Clock.tick returns the number of milliseconds passed since the previous call. If you call it in the application loop,

Framerate affect the speed of the game

 ̄綄美尐妖づ 提交于 2020-12-18 04:50:21
问题 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 pygame.time.Clock.tick function but the speed of the character was changing depending on the number of FPS, which I don't want. 回答1: pygame.time.Clock.tick returns the number of milliseconds passed since the previous call. If you call it in the application loop,

Pygame snake velocity too high when the fps above 15 [duplicate]

泪湿孤枕 提交于 2020-11-29 11:16:16
问题 This question already has an answer here : Framerate affect the speed of the game (1 answer) Closed last month . 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 found to work, high fps with slow speed. However at that point, I could not get the X and Y to be correct so that I can eat the apple. I