News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_redbox

Tile-map background collision detection

Started by redbox, 15:53, 16 December 10

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

redbox

If you are using a tile-map for a background (like this example by Kev) and have a sprite (with co-ordinates X and Y), what is the best way to check for collisions against the tile-map?  I am familiar with how you do it on other platforms, but before I start to code something it would be nice to hear if anyone has done it really effectively on the CPC. 

Do you convert where the sprite is going to be (such as in standard collision detection) into a number that can be checked in the tile-map array?  Or is there some other way of doing it?

fano

Yes , i convert screen coords to map coords to do point test.
"NOP" is the perfect program : short , fast and (known) bug free

Follow Easter Egg products on Facebook !

arnoldemu

Quote from: fano on 07:29, 17 December 10
Yes , i convert screen coords to map coords to do point test.
I do the same.

You can reduce the number of tiles you check depending on your movement.

e.g. if you are just moving right, you can just check the right column of tiles you have moved into, and only do the check one time when you have moved into new tiles.

but still I take the sprite coords, work out the bounds in map tiles, and check the tiles in the map.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

TFM

My method uses just one CP instruction and I have to check only if the sprite crosses the border from one tile to another.
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Powered by SMFPacks Menu Editor Mod