|
SpriteHit | ||
HitSpriteIndex = SpriteHit(CheckSprite, SpriteIndex, CollisionClass) | ||
Parameters: CheckSprite = The Index of the sprite to check for collisions SpriteIndex = The Index of the sprite you wish to start checking from CollisionClass = The collision class to limited sprite collisions against |
||
Returns: HitSpriteIndex = The sprite index of the first sprite that has hit the source sprite |
||
The SpriteHit function checks a sprite for any collisions against the activate sprite list. It's important to understand that SpriteHit does not simply check a pair of sprites for a collision (see SpritesOverlap for that), rather it will automatically step through the internal sprite list for you. SpriteHit will start checking for collision at your selected starting sprite ( providing this sprite exists) and will continue until either an impact is found, or it reaches the end of the sprite list. Your starting sprite will generally be the first sprite in the sprite list. Which is obtained by calling the GetFirstSprite() function. When a collision is detected, the index of the hit sprite will be returned, if there was no collision, the function returns a zero. You can check for multiple impacts, by calling SpriteHit repeatedly, each time telling it to start checking at the next sprite after the previous hit sprite. Use the GetNextSprite() function for this. It's important to remember that sprites are stored internally in what is called a linked list. This means the sprite list isn't actually ordered based upon the sprites index numbers as you might expect, but rather, the order will follow when the sprites were created, regardless of their sprite index value. For example. If you create sprites 10,5,20,2 Then when SpriteHit steps through the sprite list, it'll check sprite 2 (the starting sprite), then 20, then 5, then 10. Please see GetFirstSprite() & GetNextSprite() about iterating through the sprite list correctly. Sprite collisions can also be selectively screened by using collision class parameter. This requires that you've previously assigned each sprite it's SpriteCollisionClass bit value. You can use these values to make a sprite belong to a particular group. More importantly, this will make SpriteHit ignore groups of sprite that it shouldn't bother return a collisions against. By default, all created sprites are assigned a collision class of 1. FACTS: * SpriteHit returns the Index of the first sprite that impacts the check sprite. * If there was No collision SpriteHit returns a zero. * Sprite collisions occur when the collision regions of any two sprites overlap. See SpriteCollisionMode for the various collision modes. * Use SpriteHitMap or SpriteHitMapPixels when performing sprite to map level collisions * See the Sprite Tutorial for more information. Mini Tutorial: This example is in 3 parts. Part 1 creates two coloured images. Part 2 then creates both out test sprite (sprite #1) and a group of randomly position sprites to check collisions again. Part 3 is the main loop, where it check for any collisions with sprite #1.
This example would output.
|
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |