Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sprite Collision.

Status
Not open for further replies.

blinkl2k

Programmer
Dec 9, 2004
2
GB
Hi, I want to check if two sprites collide then do something so I write:

if sprite(1) collides sprite(2) then
...
end if

But for some reason it does not work. If anyone could show me how to fix this I'd be very greatful. Thanks
 
You can do this using the INTERSECTS or INSIDE function.

1.Intersects
--Checks to see a sprite intersects another
--If the sprite's ink is set to matte it uses the actual outline of the sprite (white pixels are the background). If the ink is anything else it uses the sprite's quad.
--Since collision is based on either the outline or the quad, if the sprites is rotated or skewd, it will still work correctly.

if sprite(1).intersects(2) then

2.Inside
--Checks to see whether a point is inside a rectangle
--Will only return true if the specified point is somewhere inside the rectangle.
--When used with sprites, a collision is only detected when the center of the sprite is somewhere inside the rectangle of another sprite.
--A sprite's rectangle does not reflect rotation or skew changes accurately.

if sprite(1).loc.inside(sprite(2).rect) then

It is quite obvious that the first one is better, but if the second works fine for your situation, use it, it less demanded on the computer.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top