SpriteVisible sets if a sprite is visible or hidden. When SpriteVisible is set to True(1) the sprite is visible (drawn), and if it's false then it's hidden.
FACTS:
* Created Sprites will default to being visible
* Hidden sprites do not return collisions
Mini Tutorial:
This example is made up of three parts. part 1 , creates from images, part 2 then creates a collection of sprites. Part 3 check for collisions between sprite #1 and the other created sprites. When a collision occurs, the sprite that was hit, is hidden. ; ======================== ; Part 1 - Create images ; ======================== Cls RGB(0,0,255) GetImage 1,0,0,32,32 Cls RGB(0,255,00) GetImage 2,0,0,32,32 ; ============================= ; Part 2- Create some sprites ; ============================= ; Create Sprite 1, and assign it image 1 CreateSprite 1 SpriteImage 1,1 CenterSpriteHandle 1 ; Enable Collision for Sprite #1 SpriteCollision 1,on ; Set Sprite #1 to collision Class %0001 SpriteCollisionClass Sprites,%0001 ; Create a bunch fo sprites to check collision against For Sprites=2 To 50 CreateSprite Sprites SpriteImage Sprites,2 x=Rnd(GetScreenWidth()-32) y=Rnd(GetScreenHeight()-32) PositionSprite sprites,x,y ; Enable Collision for this sprite SpriteCollision Sprites,on ; Set sprite to Collision Class %0010 SpriteCollisionClass Sprites,%0010 Next ; ============================= ; Part 3- The Main Loop ; ============================= ; Start a DO/Loop Do ; Clear the screen Cls RGB(0,0,0) ; Display a message Print "Hit Sprites to Hide Them" Print "Press Space to Show ALL sprites" ; Position the Sprite 1 at the mouses position PositionSprite 1,MouseX(),MouseY() ; Check if sprite #1 hit another sprite ThisSprite=SpriteHit(1,GetFirstSprite(),%0010) ; If there was an impact, then we loop through and ; find any other sprites we might have hit also While ThisSprite>0 Print "Hide Sprite:"+Str$(ThisSprite) ; Hide the sprite SpriteVisible thisSprite,false ; Check if this sprite hit another sprite ? NextSprite=GetNextSprite(ThisSprite) ThisSprite=SpriteHit(1,NextSprite,%0010) EndWhile ; Check if the SpaceKey is pressed If SpaceKey()=true ; Loop through all the created sprites and make them visible ThisSprite=GetFirstSprite() While ThisSprite>0 SpriteVisible ThisSprite,true ThisSprite=GetNextSprite(ThisSprite) EndWhile EndIf ; Draw All of the sprites DrawAllSprites ; Draw the screen Sync ; Loop back to the DO statement Loop |
This example would output.
|