Search code examples
xnacollision-detectionlayercollision

Adding "objects collisions" in the "collisions layer"


Currently, my Character uses a collision layer with pixel-Perfect. I added some objects like "doors" or "Platforms" in my game, but my character pass through them.

I think I could modify the collision layer each Update() with something like "merging". Merging the collision layer with every objects I suppose, but I don't know how to do it...

[edited] Q1 : how to merge some Texture2D in one ?

Thx for reading, hope you'll guide me.


Solution

  • You can achieve this using RenderTargets. Here's a related question on how to use them.

    Basically, you can draw all your collision sprites to the render target, making a single texture out of multiple ones. You can do this on each frame if your collision layer changes often.

    Hope this helps!

    Edit: Here's the MSDN article on RenderTargets

    More edits: Alternatively, you could check your per-pixel collision on each of the objects instead of merging them all into one. However, you would have to show some code in order to get help for that.