【发布时间】:2016-04-13 11:12:53
【问题描述】:
在下面的代码中,我在 self.rect 中添加了一个 center 和一个 top 和一个 left 属性(这仅用于学习和理解 pygame 行为)。当我添加顶部属性时,顶部似乎会被中心覆盖,但是在中心出现之前有一个左边会改变块的 x 位置。谁能解释为什么左边没有被中心覆盖?
import pygame
pygame.init()
screen=pygame.display.set_mode((500,500))
class Block(pygame.sprite.Sprite):
def __init__(self):
super(Block, self).__init__()
self.image=pygame.Surface((50,50))
self.image.fill((0,0,200))
self.rect=self.image.get_rect(top=400,center=(0,0))
#this will obviously be overwritten by center, but not the following, why?
#self.rect=self.image.get_rect(left=400,center=(0,0))
b=Block()
blockGrp=pygame.sprite.Group()
blockGrp.add(b)
print blockGrp
while 1:
pygame.time.wait(50)
for e in pygame.event.get():
if e.type==pygame.QUIT:
pygame.quit()
blockGrp.draw(screen)
pygame.display.flip()
【问题讨论】: