2
我无法弄清楚如何排序的问题是,当我将一块碎片拖到另一块碎片上时,第二块碎片也会随着第一块一起拖动。我尝试了几种方法来限制鼠标的选择,但都失败了。任何人都可以帮助 - 毫无疑问,有一个简单的方法!剪我所有的失败尝试的代码如下:用鼠标拖动组中的一个精灵
# In main loop:
# Watch for keyboard and mouse events
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_held = True
if event.type == pygame.MOUSEBUTTONUP:
mouse_held = False
# Update pieces that are in a sprite.Group()
pieces.update(mouse_held)
# In sprite class:
def update(self, mouse_held):
if mouse_held == True:
self.mouse_coordinates = pygame.mouse.get_pos()
if self.rect.collidepoint(self.mouse_coordinates) == True:
self.rect.centerx = self.mouse_coordinates[0]
self.rect.centery = self.mouse_coordinates[1]
谢谢,我也不会很快发现解决方案。为了完整性起见,我不得不适应/修改代码: 尝试: 活性=分钟(子画面,键= attrgetter(“RECT”)) 除了ValueError异常: 打印(“空的地方选择,所以子画面列表为空”) 和: 如果mouse_held: 尝试: active.update() 除了UnboundLocalError: 打印( '积极不设置,以因前一个异常') – rms9