pygame-tick

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

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,

How do I stop more than 1 bullet firing at once?

我的未来我决定 提交于 2020-12-17 07:12:44
问题 import pygame pygame.init() red = 255,0,0 blue = 0,0,255 black = 0,0,0 screenWidth = 800 screenHeight = 600 gameDisplay = pygame.display.set_mode((screenWidth,screenHeight)) ## screen width and height pygame.display.set_caption('JUST SOME BLOCKS') ## set my title of the window clock = pygame.time.Clock() class player(): ## has all of my attributes for player 1 def __init__(self,x,y,width,height): self.x = x self.y = y self.height = height self.width = width self.vel = 5 self.left = False self

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

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

一个人想着一个人 提交于 2020-07-17 10:20:13
问题 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 " + str(pygame.time.get_ticks())) clock.tick(1) According to the api for get_ticks() : Returns the number of millisconds since pygame.init() was called. Before pygame is initialized this will always be 0. But clock.tick() : This method should be called once per frame. It will compute how many . milliseconds have