|
GetNextSprite | |||
SpriteIndex = GetNextSprite(SpriteIndex) | |||
Parameters: SpriteIndex = The sprite index you wish to query |
|||
Returns: SpriteIndex = The Next Sprite Index after the sprite yo |
|||
The GetNextSprite function returns the Index of the Next Sprite after the Sprite you've queried. Active sprites, like all resources in PlayBasic are internally managed through a linked list. Each time a new sprite is created (regardless of it's sprite index), it's placed at the head of the list. So sprites are linked together from the most recently created sprite (the newest), to the oldest sprite. To traverse the sprite list, first we need to the grab the head sprite from PlayBasics internal linked list. We do this using GetFirstSprite. This command grabs the most recently created sprite from the head of sprite list for us. Once we have the first sprite in the list, we can then step through all the created sprites using GetNextSprite. I.e This sample code steps through the entire sprite list.
PlayBasic uses the linked list in everything from rendering to collsion (ie. DrawAllSprites, DrawOrderedSprites, SpriteHit) While we could also step through the sprite list and render them using DrawSprite, We'll most commonly be using GetFirstSprite, GetNextSprite commands in conjunction with the sprite collision. (See: SpriteHit). FACTS: * GetNextSprite() will return a ZERO if there is no next sprite. * The sprite list will be in order the sprites were created, and not the sprites index numbers. * See GetFirstSprite Mini Tutorial: This first part of example creates 10 sprites. The sprite indexes will be between 100 and 110. Then in the second part, we use the GetFirstSprite and functions to step through our list of created sprites.
This example would output.
|
Related Info: | CreateSprite | GetFirstSprite | GetFreeSprite | NewSprite | SpriteHit : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |