Skip to content

Commit

Permalink
Add info about collection proxies (#418)
Browse files Browse the repository at this point in the history
* add info about collection proxies

* remove unneed info

* add more info
  • Loading branch information
AGulev authored Apr 7, 2024
1 parent 8065f21 commit 8ce72d0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions docs/en/manuals/physics-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ Previously, physics interactions in Defold were handled by broadcasting messages

## Setting the Physics World Listener

To start using this new functionality, you need to use the `physics.set_listener` function. This function takes a callback as its argument, which will be called with information about all physics interactions in the world. The general syntax is as follows:
In Defold, each collection proxy creates its own separate physics world. Therefore, when you are working with multiple collection proxies, it's essential to manage the distinct physics worlds associated with each. To ensure that physics events are handled correctly in each world, you must set a physics world listener specifically for each collection proxy's world.

```lua
physics.set_listener(function(self, event, data)
-- Event handling logic goes here
end)
This setup means that the listener for physics events must be set from within the context of the collection that the proxy represents. By doing so, you associate the listener directly with the relevant physics world, enabling it to process physics events accurately.

Here is an example of how to set a physics world listener within a collection proxy:

```lua
function init(self)
-- Assuming this script is attached to a game object within the collection loaded by the proxy
-- Set the physics world listener for the physics world of this collection proxy
physics.set_listener(physics_world_listener)
end
```

By implementing this method, you ensure that each physics world generated by a collection proxy has its dedicated listener. This is crucial for handling physics events effectively in projects that utilize multiple collection proxies.

::: important
If a listener is set, [physics messages](/manuals/physics-messages) will no longer be sent.
If a listener is set, [physics messages](/manuals/physics-messages) will no longer be sent for the physics world where this listener is set.
:::

## Event Data Structure
Expand Down

0 comments on commit 8ce72d0

Please sign in to comment.