Hi everyone,
The map in my game is top down 2D, and I’m using the physics engine for collision detection between sprites and “solid” tiles e.g. buildings etc. Until now, I’ve been adding a physics object for every tile with the “physics=true” property set in Tiled i.e.:
local ifPhysicsProperty = function (event) mte.physics.addBody(event.target, "static", {friction = 0.5, bounce = 0.0, density = 1}) end
mte.addPropertyListener("physics", ifPhysicsProperty)
However, I noticed there were a lot of unnecessary physics objects being created, as adjacent tiles would ideally be part of a single physics object rather than separate objects.
So I’ve made a function which will rope together adjacent solid tiles and create a single physics object. I’d be happy to post the code if anyone’s interested.
For example this:
[sharedmedia=core:attachments:2380]
Can be simplified to this:
[sharedmedia=core:attachments:2381]
11 physics objects reduced to 4. In some of my other maps this approach has cut down on the number of physics object by about 10x.
I just wanted to share this in case anyone else has been curious about doing the same thing!
- Anthony