def move(self, sprite, x, y, absolute=False):
"""
This will 'overwrite' the normal Sprite's `move` method by Component's extend.
:param Sprite sprite: the GameObject that this Component belongs to (the Sprite to move around)
:param Union[int,None] x: the amount in pixels to move in x-direction
:param Union[int,None] y: the amount in pixels to move in y-direction
:param bool absolute: whether x and y are given as absolute coordinates (default: False): in this case x/y=None means do not move in this dimension
"""
orig_x = sprite.rect.x
orig_y = sprite.rect.y
# first call the original Sprite's move method
sprite._super_move(x, y, absolute)
# move all our docked Sprites along with us
if not absolute:
for docked_sprite in self.docked_sprites:
docked_sprite.move(x, y, absolute=False)
else:
# translate into relative movement: we don't want the docked components to move to the given mothership's absolute values
x_move = x - orig_x if x is not None else 0
y_move = y - orig_y if y is not None else 0
for docked_sprite in self.docked_sprites:
docked_sprite.move(x_move, y_move)
评论列表
文章目录