CPCWiki forum

General Category => Programming => Topic started by: redbox on 15:53, 16 December 10

Title: Tile-map background collision detection
Post by: redbox on 15:53, 16 December 10
If you are using a tile-map for a background (like this example (http://www.cpctech.org.uk/source/tilemap.html) 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?
Title: Re: Tile-map background collision detection
Post by: fano on 07:29, 17 December 10
Yes , i convert screen coords to map coords to do point test.
Title: Re: Tile-map background collision detection
Post by: arnoldemu on 10:21, 17 December 10
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.
Title: Re: Tile-map background collision detection
Post by: TFM on 18:20, 17 December 10
My method uses just one CP instruction and I have to check only if the sprite crosses the border from one tile to another.
Powered by SMFPacks Menu Editor Mod