pygame.display.update() 在循环中不起作用
pygame.display.update() doesn't work in a loop
我正在开发一个简单的游戏。当我循环绘制某些东西时,它绘制它的时间不到一秒钟。这是我的代码:
import pygame, sys
from pygame.locals import*
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((1000, 750))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('Game')
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEMOTION:
"do something"
else:
posx, posy = pygame.mouse.get_pos()
if event.type == pygame.MOUSEBUTTONUP:
if posx == 500 and posy == 500:
DISPLAYSURF.fill((40, 40, 40))
pygame.draw.rect(DISPLAYSURF, (40, 40, 40), (posx, posy, 50, 20))
pygame.display.update()
我做错了什么?
仅当鼠标位于 500,500 并且触发事件 MOUSEBUTTONUP 时才更新显示。我会将其更改为:
import pygame, sys
from pygame.locals import*
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((1000, 750))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('Game')
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEMOTION:
"do something"
else:
posx, posy = pygame.mouse.get_pos()
if event.type == pygame.MOUSEBUTTONUP:
if posx == 500 and posy == 500:
DISPLAYSURF.fill((40, 40, 40))
pygame.draw.rect(DISPLAYSURF, (40, 40, 40), (posx, posy, 50, 20))
pygame.display.update()
我正在开发一个简单的游戏。当我循环绘制某些东西时,它绘制它的时间不到一秒钟。这是我的代码:
import pygame, sys
from pygame.locals import*
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((1000, 750))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('Game')
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEMOTION:
"do something"
else:
posx, posy = pygame.mouse.get_pos()
if event.type == pygame.MOUSEBUTTONUP:
if posx == 500 and posy == 500:
DISPLAYSURF.fill((40, 40, 40))
pygame.draw.rect(DISPLAYSURF, (40, 40, 40), (posx, posy, 50, 20))
pygame.display.update()
我做错了什么?
仅当鼠标位于 500,500 并且触发事件 MOUSEBUTTONUP 时才更新显示。我会将其更改为:
import pygame, sys
from pygame.locals import*
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((1000, 750))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('Game')
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEMOTION:
"do something"
else:
posx, posy = pygame.mouse.get_pos()
if event.type == pygame.MOUSEBUTTONUP:
if posx == 500 and posy == 500:
DISPLAYSURF.fill((40, 40, 40))
pygame.draw.rect(DISPLAYSURF, (40, 40, 40), (posx, posy, 50, 20))
pygame.display.update()