gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Collision between Sprite an Tiles in TileMode

#34987 - Mitch GBA - Sat Jan 29, 2005 12:18 am

I've been progressing alot, by asking for advise on this forum, so I'll ask another question and learn :) I've made a map, and I've got both that map and the sprite on the screen. Now I'd like to know how you can check for collision between that sprite and the tiles, caus for as far as I know, the position of the tiles change when scrolling, and coordinates are always calculated from the left-top point of the screen right? Anyone can explain me how, or direct me to a tutorial, to know if the sprite is at the position of the tile? ( thus colliding)

Thanks
-Mitch

#34989 - Mucca - Sat Jan 29, 2005 12:33 am

Maintain logical information on sprite and level, independant of display information. Minimum you need would be position and bounding box of sprite, and areas within level which are 'solid'. Start out with rectangles, define them and store them in an array, and anytime a sprite tries to move check its new logical position to see if it collides with any solid areas. Dont worry about optimising the process until you get it working, but rest assured there's plenty you can do later to speed it up.

Don't try to base collision detection on tiles or even map information, they're graphical elements, not logical.

#35065 - tepples - Sun Jan 30, 2005 12:14 am

Mucca wrote:
Don't try to base collision detection on tiles or even map information, they're graphical elements, not logical.

That is, unless you use the same logical information to generate both the graphics and the collision data, which was the case in most NES games.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#35173 - Miked0801 - Mon Jan 31, 2005 8:15 pm

Circles are easy to detect as well and fast

deltaX squared + deltaY squared = distance between points squared.

2 subs, 2 muls, an add, and a compare to get the distance between any 2 points. Faster than most rect based systems.

#35175 - LOst? - Mon Jan 31, 2005 8:37 pm

Miked0801 wrote:
Circles are easy to detect as well and fast

deltaX squared + deltaY squared = distance between points squared.

2 subs, 2 muls, an add, and a compare to get the distance between any 2 points. Faster than most rect based systems.


Interesting to see that you use 2 muls instead of the square root.

Now do you have any solution for detecting 3 balls where 1 ball is moving and the other two are just static position'd?
I have the problem of detecting a hit from more than one ball. Help!