您将图像blit到表面上以用作背景.然后按下按钮X在同一表面上显示图像,如何删除图像?到目前为止,我有这个,但后来我的背景中间有一个白色的矩形.
screen = pygame.display.set_mode(1280, 512)
screen.blit(background, (0,0))
while True:
pygame.display.flip() #flip is same as update
for event in pygame.event.get():
if (event.type == pygame.KEYDOWN):
if event.key == pygame.K_SPACE:
screen.blit(player, (x, y))
if event.key == pygame.K_BACKSPACE:
pygame.draw.rect(screen, [255,255,255], (x, y, 62,62))
Run Code Online (Sandbox Code Playgroud) 另外我的另一篇文章.如果我有一个坐标列表,我如何将它们分配给变量并继续追加和分配:
positions = [(1,1), (2,4), (6,7)]
index = 0
for looper in range(0, len(positions)):
posindex = positions[index]
index = index + 1
Run Code Online (Sandbox Code Playgroud)
其中posindex是pos0,然后是pos1,然后是pos2并随着变量索引而增加,这也将给出列表中的索引.Python给了我这个:
"'posindex' is undefined"
Run Code Online (Sandbox Code Playgroud)
无论如何将变量放入另一个变量?我可能遇到的任何其他问题?