Skip to content

Commit

Permalink
fix: multiple when_touching
Browse files Browse the repository at this point in the history
  • Loading branch information
koen1711 committed Dec 11, 2024
1 parent e7c289c commit 196620c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion play/core/physics_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def simulate_physics():
for _ in range(_NUM_SIMULATION_STEPS):
# the smaller the simulation step, the more accurate the simulation
physics_space.step(1 / (FRAME_RATE * _NUM_SIMULATION_STEPS))
_update_sprites()
_update_sprites(True)
34 changes: 17 additions & 17 deletions play/core/sprites_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,11 @@ def _update_sprites(skip_user_events=False): # pylint: disable=too-many-branche
sprites_group.update()

for sprite in sprites_group.sprites():
#################################
# @sprite.when_touching events
#################################
if sprite._active_callbacks:
for cb in sprite._active_callbacks:
run_callback(
cb,
[],
[],
)
if skip_user_events:
continue

sprite._is_clicked = False
if sprite.is_hidden:
continue

######################################################
# update sprites with results of physics simulation
######################################################
if sprite.physics and sprite.physics.can_move:

body = sprite.physics._pymunk_body
angle = _math.degrees(body.angle)
if isinstance(sprite, Line):
Expand All @@ -60,6 +43,23 @@ def _update_sprites(skip_user_events=False): # pylint: disable=too-many-branche
angle # needs to be .angle, not ._angle so surface gets recalculated
)
sprite.physics._x_speed, sprite.physics._y_speed = body.velocity
if skip_user_events:
continue

#################################
# @sprite.when_touching events
#################################
if sprite._active_callbacks:
for cb in sprite._active_callbacks:
run_callback(
cb,
[],
[],
)

sprite._is_clicked = False
if sprite.is_hidden:
continue

#################################
# @sprite.when_clicked events
Expand Down

0 comments on commit 196620c

Please sign in to comment.