UnderwareDESIGN

PlayBASIC => Beginners => Topic started by: thaaks on August 30, 2005, 06:48:49 AM

Title: Collisions between Sprites and Maps?
Post by: thaaks on August 30, 2005, 06:48:49 AM
Me again - I was wondering if there is a way to check if a sprite collides with a map.

I know that there is a function which tests if a certain rectangle collides with parts of the map (used in the platformer demo).

What about all those new collision modes for sprites and their usage in maps? Wouldn't it make sense to have a collision test function for maps which takes a sprite as parameter?

I want to move a ball in a map and want to check if the ball (and not the square around the ball) collides with the map.

Thanks,
Tommy
Title: Collisions between Sprites and Maps?
Post by: kevin on August 30, 2005, 09:06:38 AM
Collisions are vector based, if you want to run circle to map, you'd peek the surrounding tiles then test the tile region to the circle using RectHitSprite.    But your actually meant to use world collision.  Which means more set up (since it'd be manual as there s no editor), but better results.

To generate a collision world for a map, just connect the tile edges to form bounding box (actually they can be any shape)  just make sure you remove and common shared walls, you could opt it join common spans etc.   Anyway, it should give you a set of convex solid spaces that represent the map.   Once you have a world,  you can run anything against it,  sprite collision, ray intersection etc.



2014 UPDATE:   This is very old information,  modern editions of PlayBASIC include all sorts of vector and pixel to pixel level collisions to maps like SpriteHitMapPixels as well as ray intersections etc etc

Related Articles:

   Hell Eagle (Map / Level Mock Up) (https://www.underwaredesign.com/forums/index.php?topic=3914.0)


   Also read -> PlayBASIC Documentation - MAP COMMANDS - MAP COLLISION (http://playbasic.com/help.php?page=MAPS.INDEX)




Title: Collisions between Sprites and Maps?
Post by: thaaks on August 30, 2005, 10:10:47 AM
QuoteTo generate a collision world for a map, just connect the tile edges to form bounding box (actually they can be any shape)  just make sure you remove and common shared walls, you could opt it join common spans etc.   Anyway, it should give you a set of convex solid spaces that represent the map.   Once you have a world,  you can run anything against it,  sprite collision, ray intersection etc.
Sounds perfect. Can you point me to some sample source code how to setup the collision shapes, join spans and such for a world?

Just to get it clear some brain dump:
Currently I already have a map in a binary file with tilebased collision information. Reading this map file I can (hopefully) setup the world bounding boxes and all map info with tiles to draw and such.
All my moving sprites would be checked against the world and its bounding boxes for collision info (and additionally against the other moving sprites using collision groups).
The map is only used for displaying the currently visible area using a camera.
Does this make sense so far?

If that works (and I hope it does!) I will buy PlayBasic immediately and become a happy and convinced PlayBasic customer and addict :D
Title: Collisions between Sprites and Maps?
Post by: thaaks on August 31, 2005, 05:35:28 AM
QuoteCan you point me to some sample source code how to setup the collision shapes, join spans and such for a world?
Some sample code or reference to some demo, anyone?

Tommy
Title: Collisions between Sprites and Maps?
Post by: thaaks on August 31, 2005, 08:35:04 AM
Problem solved, the sliding world collision demo should help me getting started.

Thanks anyway,
Tommy