|
@@ -9,17 +9,24 @@ Previously, physics interactions in Defold were handled by broadcasting messages
|
|
|
|
|
|
## Setting the Physics World Listener
|
|
## 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
|
|
::: 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
|
|
## Event Data Structure
|