News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Collisions between Sprites and Maps?

Started by thaaks, August 30, 2005, 06:48:49 AM

Previous topic - Next topic

thaaks

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

kevin

#1
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)


   Also read -> PlayBASIC Documentation - MAP COMMANDS - MAP COLLISION





thaaks

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

thaaks

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

thaaks

Problem solved, the sliding world collision demo should help me getting started.

Thanks anyway,
Tommy