News:

Function Finder  Find all the functions within source code files

Main Menu

Transparancy and collision detection

Started by Topdecker, August 08, 2005, 12:00:08 AM

Previous topic - Next topic

Topdecker

Hi!

I've spent more than a few hours working on this, so my apologies in advance if I might appear as if I haven't tried to do my homework.

Ok, I just wanted to confirm that when you are detecting collisions between sprites, that transparent portions of a sprite are used when you are determining if a collision occurs.

There wouldn't be a code snippet around that illustrates how to further examine a collision, allowing me to determine if the "hit" was in a transparent area?

Thanks!

Tim

kevin

#1
Collisions in PB are both vector and pixel based.  If you want to emulate any type of 'per pixel' collisions you'll need to use the sprites "Shape Mode'.  

At this point, you'll have to define your images shape manually.  I've not had time to write a sprite collision shape editor..

Current Modes
 
0 = Rect
1 = Rotated Rect
2 = Circular
3 = shape
4 = sliding
5 = sticky collsiion
6 = Pixel Perfect collisions

Check the SpriteCollisionMode command in the help.  There's a few tidbit examples in the   Example/Sprites folder also


Anyway, The default collision mode is Rect.   In this mode SpriteHit will return a True when the regions overlap. The actual pixels within the image are not considered.


Obsolete Information Updated 2012: Pixel Perfect collision modes were added to PlayBASIC many years ago. 



Topdecker

QuoteAt this point, you'll have to define your images shape manually.  I've not had time to write a sprite collision shape editor..

I saw references to defining a shape, but never could find anything that explained how a shape was defined.

The shape that I am working with is very primitive.  It is a hexagon.  Hexagons are often used in wargames and the map that I am working on is only 150 or so hexes, so I thought that a speedy way to make a map would be to create a hexagonal sprite.

So are there any documents about defining shapes and using them within PlayBasic?

Thanks!

Tim

kevin

There's tidbits about shapes in the doc's under the shapes section.  But there's not a tutorial as such.

in a nut shell, shapes have two things.  

1) a list of vertex (points)

2) a list of edges..


So to make a box shape 100x by 200y,  you'd create a shape with provision for 4 vertex and 4 edges

vertex 1 could be set to 0x,0y
vertex 2 could be set to 100x,0y
vertex 3 could be set to 100x,200y
vertex 4 could be set to 100x,200y


Then you'd deifne the four edges

edge #1  would connect  verts   1 to 2
edge #2  would connect  verts   2 to 3
edge #3  would connect  verts   3 to 4
edge #4  would connect  verts   4 to 1


and that's about it really..

Topdecker

QuoteThere's tidbits about shapes in the doc's under the shapes section.  But there's not a tutorial as such.

in a nut shell, shapes have two things.  

1) a list of vertex (points)

2) a list of edges..

Thanks, I appreciate the help.  I think that the example should get me going again - I didn't know that I had it to work with.

ImageShape was the command that I was "missing" and hopefully it will be a while before I ask for help again.


Tim

kevin

Cool, glad your on track..   But please your welcome to throw out as many questions as you need.    So when it doubt fire away