本文整理汇总了Python中Mouse.get_pos方法的典型用法代码示例。如果您正苦于以下问题:Python Mouse.get_pos方法的具体用法?Python Mouse.get_pos怎么用?Python Mouse.get_pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mouse
的用法示例。
在下文中一共展示了Mouse.get_pos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: import Mouse [as 别名]
# 或者: from Mouse import get_pos [as 别名]
def update(self, *args):
layers = GetGame().get_layers()
def sort_sprites_cmp(x, y):
# Sorts sprites by layer from top down
return layers.index(y.layer) - layers.index(x.layer)
self._sprites.sort(sort_sprites_cmp)
# Let's handle mouse clicks first
for event in Mouse.get_events():
if event.type == pygame.MOUSEMOTION:
# We don't really care about these, we'll poll the
# mouse directly later
continue
for sprite in self._sprites:
if not isinstance(sprite, MouseClickSprite):
continue
if sprite.is_clicked(event):
sprite.clicked(event)
if sprite.click_overlay is not True:
break
# Now let's handle mouseover.
mouse_pos = Mouse.get_pos()
mouse_now_over = []
for sprite in self._sprites:
if not isinstance(sprite, MouseOverSprite):
continue
if sprite.is_mouse_over(mouse_pos):
mouse_now_over.append(sprite)
# first, is this one that the mouse was previously over
if sprite in self._mouse_previously_over:
if sprite.hover_overlay:
continue
else:
break
# Now that we know it's not, we tell it the mouse is on it
sprite.mouse_on()
if sprite.hover_overlay:
continue
break
for sprite in self._mouse_previously_over:
if sprite in mouse_now_over:
continue
sprite.mouse_off()
self._mouse_previously_over = mouse_now_over
Group.update(self, *args)