[英]Is it possible to have my program draw a shape with pygame, wait a second, and then draw another? But, I still want the rest of the program to run
我試圖為我的最終項目制作一個節奏游戲。 我正在使用 pygame,我希望我的程序根據我正在播放的音樂繪制一個形狀,稍等片刻,然后再繪制另一個。 我的程序是否可以在繪制每個形狀之間等待一秒鍾,但程序的其余部分仍在運行? (不是 pygame.time.delay())
我試過http://fredericiana.com/2014/11/14/settimeout-python-delay/要么沒有用,要么我沒能正確實現
def spawnShapesGameOne(gameInPlay, gameInPlayOne,drawShapesOne):
if gameInPlay == True:
if drawShapesOne == True:
pygame.draw.rect(surface, GREEN,(w*.23, h*.25, w*.05,w*.05))
#Wait one second
pygame.draw.rect(surface, GREEN,(w*.73, h*.25, w*.05,w*.05))
#Wait one second
pygame.draw.rect(surface, GREEN,(w*.73, h*.65, w*.05,w*.05))
#Wait one second
pygame.draw.rect(surface, GREEN,(w*.23, h*.65, w*.05,w*.05))
您可以使用時間模塊或任何計時器來執行此非阻塞延遲/調度:
注意:我將重置計時器移動到主循環
import time
timer1sec = 0
def draw_myshape():
# your drawing code here
# main pygame loop
while True:
if time.time() - timer1sec >= 1: # if one seconds passed
draw_myshape()
timer1sec = time.time() # reset our timer
# rest of pygame code here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.