|
GetFirstSprite | |||
FirstSpriteIndex = GetFirstSprite() | |||
Parameters: NONE | |||
Returns: FirstSpriteIndex = The Index of the First sprite in the sprite list |
|||
The GetFirstSprite function returns the Index of the last created Sprite in the internal sprite list. 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. What GetFirstSprite does, is grabs the sprite index from the head of the list, whatever it might be. 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. (SeeSpriteHit). FACTS: * GetFirstSprite() will return a ZERO if the sprite list is empty. * The sprite list will be in order the sprites were created, and not the sprites index numbers. 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 GetNextSprite functions to step through our list of created sprites.
This example would output.
|
Related Info: | CreateSprite | DeleteSprite | GetFreeSprite | GetNextSprite | NewSprite | SpriteHit : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |