From 33bc41f908a5a9c23ca98764d27720067d64cd39 Mon Sep 17 00:00:00 2001 From: AGulev Date: Sat, 6 Apr 2024 18:28:23 +0200 Subject: [PATCH] add info about collection proxies --- docs/en/manuals/physics-events.md | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/en/manuals/physics-events.md b/docs/en/manuals/physics-events.md index b4bf3ef4..81bca193 100644 --- a/docs/en/manuals/physics-events.md +++ b/docs/en/manuals/physics-events.md @@ -9,15 +9,26 @@ 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. + +--- + +This update should make it clear that each collection proxy creates a new physics world and that listeners must be set within each respective collection proxy to manage physics events properly. + ::: important If a listener is set, [physics messages](/manuals/physics-messages) will no longer be sent. :::