为什么赢了';PyGame中的屏幕是否刷新?
我对PyGame比较陌生。我试图制作一个简单的程序,在屏幕上显示一个表示鼠标位置的字符串为什么赢了';PyGame中的屏幕是否刷新?,pygame,Pygame,我对PyGame比较陌生。我试图制作一个简单的程序,在屏幕上显示一个表示鼠标位置的字符串 import pygame, sys from pygame.locals import * pygame.init() screen = pygame.display.set_mode((400,400),0,32) myFont = pygame.font.SysFont('arial', 14) while True: for event in pygame.event.get():
import pygame, sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((400,400),0,32)
myFont = pygame.font.SysFont('arial', 14)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
x,y = pygame.mouse.get_pos()
label = myFont.render('mouse coords: ' + str(x) + ', ' + str(y), 1, (0,128,255))
screen.blit(label, (10,10))
pygame.display.update()
当我移动鼠标时,标签会变得模糊,直到文本无法阅读为止。我确信我正确地调用了screen.blit()和pygame.display.update(),但是标签似乎没有更新!任何帮助都会很好。你需要做的是在循环中添加一个背景,因为我们正在做的是在每个鼠标上添加一个鼠标单词 这样做:
import pygame, sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((400,400),0,32)
myFont = pygame.font.SysFont('arial', 14)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
x,y = pygame.mouse.get_pos()
label = myFont.render('mouse coords: ' + str(x) + ', ' + str(y), 1, (0,128,255))
screen.fill((0,0,0))
screen.blit(label, (10,10))
pygame.display.update()
通过这种方式,在每次更新之间用黑色填充屏幕,这样鼠标位置将被闪烁,然后通过填充清除,然后新位置将被闪烁,等等,你需要做的是在循环中闪烁背景,因为我们所做的是在每个鼠标上闪烁鼠标单词 这样做:
import pygame, sys
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((400,400),0,32)
myFont = pygame.font.SysFont('arial', 14)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
x,y = pygame.mouse.get_pos()
label = myFont.render('mouse coords: ' + str(x) + ', ' + str(y), 1, (0,128,255))
screen.fill((0,0,0))
screen.blit(label, (10,10))
pygame.display.update()
通过这种方式,在每次更新之间用黑色填充屏幕,这样鼠标位置将闪烁,然后通过填充清除鼠标位置,然后新位置将闪烁,依此类推在绘制逻辑开始时,首先使用
screen.fill(颜色(“黑色”)
。首先使用screen.fill(颜色(“黑色”)清除屏幕)
,在绘制逻辑的开始处。