如何让整个场景不可见,pygame
How do I make the whole scene invisible, pygame
我正在尝试制作一个游戏,如果有人按下左键,pygame 会画一个圆,然后画一条线将圆连接到左上角。如果 he/she 按右键单击,它会从屏幕上删除所有创建的内容。我想过用一个大的黑色方块覆盖所有东西,但这并不是真正清除屏幕,只是覆盖它。我的代码如下:
from pygame import *
init()
size = width, height = 650, 650
screen = display.set_mode(size)
button = 0
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
def drawScene(screen, button):
# Draw circle if the left mouse button is down.
if button==1:
draw.circle(screen,GREEN,(mx,my), 10)
draw.line(screen,GREEN, (0,0),(mx,my))
if button == 3:
mouse.set_visible(False)
display.flip()
running = True
myClock = time.Clock()
# Game Loop
while running:
for e in event.get(): # checks all events that happen
if e.type == QUIT:
running = False
if e.type == MOUSEBUTTONDOWN:
mx, my = e.pos
button = e.button
drawScene(screen, button)
myClock.tick(60) # waits long enough to have 60 fps
quit()
在这种情况下请指导我。提前致谢。
I thought about just covering everything with a big black square, but that is not really clearing the screen, just covering it.
cover和clear没有任何区别。屏幕由像素组成。绘制对象只是改变像素的颜色。绘制黑色方块会再次改变像素的颜色。
请注意,pygame.draw.circle()
and pygame.draw.line()
等操作不会创建任何对象。它们只是更改传递给操作的表面某些像素的颜色。
清除整个window最简单的方法是pygame.Surface.fill()
:
screen.fill((0, 0, 0))
分别
screen.fill(BLACK)
在计算机图形学中,没有 "clearing" 屏幕这样的东西。您只能用新像素覆盖以前的绘图。你画一个黑色大矩形的想法会很完美,但我使用 screen.fill(0)
可能更有效
我正在尝试制作一个游戏,如果有人按下左键,pygame 会画一个圆,然后画一条线将圆连接到左上角。如果 he/she 按右键单击,它会从屏幕上删除所有创建的内容。我想过用一个大的黑色方块覆盖所有东西,但这并不是真正清除屏幕,只是覆盖它。我的代码如下:
from pygame import *
init()
size = width, height = 650, 650
screen = display.set_mode(size)
button = 0
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
def drawScene(screen, button):
# Draw circle if the left mouse button is down.
if button==1:
draw.circle(screen,GREEN,(mx,my), 10)
draw.line(screen,GREEN, (0,0),(mx,my))
if button == 3:
mouse.set_visible(False)
display.flip()
running = True
myClock = time.Clock()
# Game Loop
while running:
for e in event.get(): # checks all events that happen
if e.type == QUIT:
running = False
if e.type == MOUSEBUTTONDOWN:
mx, my = e.pos
button = e.button
drawScene(screen, button)
myClock.tick(60) # waits long enough to have 60 fps
quit()
在这种情况下请指导我。提前致谢。
I thought about just covering everything with a big black square, but that is not really clearing the screen, just covering it.
cover和clear没有任何区别。屏幕由像素组成。绘制对象只是改变像素的颜色。绘制黑色方块会再次改变像素的颜色。
请注意,pygame.draw.circle()
and pygame.draw.line()
等操作不会创建任何对象。它们只是更改传递给操作的表面某些像素的颜色。
清除整个window最简单的方法是pygame.Surface.fill()
:
screen.fill((0, 0, 0))
分别
screen.fill(BLACK)
在计算机图形学中,没有 "clearing" 屏幕这样的东西。您只能用新像素覆盖以前的绘图。你画一个黑色大矩形的想法会很完美,但我使用 screen.fill(0)