Collision
Root / Programming Questions / [.]
zagg2000Created:
BG layers aren't really all that much different from the text layer. You can move it around with pixel precision and have a much larger more colorful set of "letters" but it is otherwise very much the same. There isn't anything in there to say if something is solid or empty. That is something you have to code and tailor for your game.
That being said you can lookup which tile is at a given tile or pixel location and react to that (BGGET I think). As there are up to four layers available you can dedicate one layer to all the solid objects, and only check against that. You could also search through the tiles at load time and keep track of your own list of bounding boxes and do collision detection against that. Or just have that list in a separate file or set of data statements and have the map be little more than a pretty picture.
The easiest and least impressive thing is to simply move a whole tile at a time accepting input only if the path is clear. As if you were still making a text mode game.
If you have more free movement I would keep track of your old position each frame. Then I would calculate your new position. I would check separately on the x and y axis if you would bump into anything inbetween the old and new positions. If so move back toward your original position until you don't hit anything.
I hope that helps.
BG layers aren't really all that much different from the text layer. You can move it around with pixel precision and have a much larger more colorful set of "letters" but it is otherwise very much the same. There isn't anything in there to say if something is solid or empty. That is something you have to code and tailor for your game. That being said you can lookup which tile is at a given tile or pixel location and react to that (BGGET I think). As there are up to four layers available you can dedicate one layer to all the solid objects, and only check against that. You could also search through the tiles at load time and keep track of your own list of bounding boxes and do collision detection against that. Or just have that list in a separate file or set of data statements and have the map be little more than a pretty picture. The easiest and least impressive thing is to simply move a whole tile at a time accepting input only if the path is clear. As if you were still making a text mode game. If you have more free movement I would keep track of your old position each frame. Then I would calculate your new position. I would check separately on the x and y axis if you would bump into anything inbetween the old and new positions. If so move back toward your original position until you don't hit anything. I hope that helps.Thanks a bunch man! that helped alot!