pygame-clock

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

pygame.display.update runs after pygame.time.wait(1000)

故事扮演 提交于 2020-02-25 06:44:25
问题 I am working through a tutorial. The tutorial can be found here https://inventwithpython.com/makinggames.pdf The main script i am referring to can be found here https://inventwithpython.com/memorypuzzle.py There is a bug in this program that I have been trying to resolve for days. In the main game loop ` while True: # main game loop mouseClicked = False DISPLAYSURF.fill(BGCOLOR) # drawing the window drawBoard(mainBoard, revealedBoxes) for event in pygame.event.get(): # event handling loop if

Counting time in pygame

梦想与她 提交于 2020-01-05 05:26:29
问题 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. I want to count from 0 when the boolean is true. import pygame pygame.init() loop = True boolean = False while loop: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key

pygame: how do I get my game to actually run at 60fps?

青春壹個敷衍的年華 提交于 2019-12-12 05:49:53
问题 In my main loop I have: clock.tick_busy_loop(60) pygame.display.set_caption("fps: " + str(clock.get_fps())) However, the readout says the game is reading at 62.5fps. I then tried to input clock.tick_busy_loop(57.5) , which gave me a readout of 58.82...fps. When I set clock.tick_busy_loop(59) I get 62.5fps again. It looks like there is a threshold between 58.8fps and 62.5fps that I can't overcome here. How do I get my game to actually run at 60fps? I'm mainly looking for this kind of control

How to set a clicking clock in a pygame window

时光毁灭记忆、已成空白 提交于 2019-12-12 03:50:06
问题 #!/usr/bin/python # -*- coding: utf-8 -*- import pygame import sys import datetime import time class TextPicture(pygame.sprite.Sprite): def __init__(self, speed, location): pygame.sprite.Sprite.__init__(self) now = datetime.datetime.now() text = now.strftime("%H:%M:%S") font = pygame.font.Font(None, 40) time_text = font.render(text, 1, [0, 0, 0]) # show now time self.image = time_text self.speed = speed self.rect = self.image.get_rect() self.rect.left, self.rect.top = location def move(self):