Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listener for when collision detection has been completed #2849

Closed
christian-mindfulness opened this issue Nov 12, 2023 · 3 comments · Fixed by #2896
Closed

Add listener for when collision detection has been completed #2849

christian-mindfulness opened this issue Nov 12, 2023 · 3 comments · Fixed by #2896

Comments

@christian-mindfulness
Copy link
Contributor

christian-mindfulness commented Nov 12, 2023

Problem to solve

In certain situations one needs to know the order in which collisions happened (during a time step). For instance if a player collides with both an enemy and the goal within the same time step. To achieve this, one can assemble a list of objects that are passed to the multiple calls to onCollision. By creating an additional callback onCollisionsCompleted which is called once all the calls to onCollision are finished, then the player has a full list of all the objects with which it collided within the time step.

Proposal

Following discussion on discord, this can be achieved by adding a Listenable object to the CollisionDetection class.

More information

I've started working on a branch for this: https://github.com/christian-mindfulness/flame/tree/add_collision_completed

@ufrshubham
Copy link
Member

Doesn't onCollisionEnd work for this?

@christian-mindfulness
Copy link
Contributor Author

onCollisionEnd is called on the time step when an object stops colliding with another. This callback will be called at the end of the time step where the collision occurs. Thus useful if an object is colliding with multiple other objects within a given time step. There's more detail on the discussion thread that I had with @spydon about a month ago:
https://discord.com/channels/509714518008528896/1157721633109311560

@christian-mindfulness christian-mindfulness changed the title Add callback for when collision detection has been completed Add listener for when collision detection has been completed Dec 2, 2023
@christian-mindfulness
Copy link
Contributor Author

I've updated the description and title to cover what we have discussed on discord.

spydon pushed a commit that referenced this issue Dec 6, 2023
Add a new variable to the `CollisionDetection` class. Call
`notifyListeners` at the end of the collision detection step, so that
users can add a listener to their code to know when this step has
finished. The variable is a basic implementation of a `Listenable`
class, since it needs no more complexity.


Closes #2849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants