views:

131

answers:

1

hey. I'm creating a 2d side scrolling game and have a question regarding the collision. I've been reading various articles and a few of them say that you should have a collision layer, which is exactly the same style as the tile layer but simply stores bits. I understand this logic, but what if my tiles are actually structs that contain a property called IsSolid. Can I not simply check if the current tile isSolid instead of having another layer? Or does having a collision layer provide further benefits that I've missed?

Thanks for any help

+2  A: 

Really it's only a big deal if your game supports multiple layers.

If you have multiple visual layers (for example: background, playfield, foreground), then it can be helpful to be able to treat all those layers in the same way. Separating out the collision data can be structurally "nice".

How you do that is up to you. You could implement a separate collision layer that you can edit separately. However I recommend against it because then you have to keep your collision layer in-sync with your visual "playfield" layer.

A better solution is to, when you load a level, dynamically generate a collision "layer" by extracting the data from your playfield layer (and perhaps other layers, if that makes sense for your game). You will probably store this "layer" in a completely different format and place to the visual data for a level.

Andrew Russell