The SpriteCollisionDebug command can allows you to enable/disable a special collision debug mode from this sprite.
When debug mode is enabled, the sprite will be rendered with the outline of it's collision modes region overlaid on top of it. It will render two shapes. The red outline will be the sprites bounding box, and the white outline will be it's actually collision zone. This can be invaluable when fine tuning sprite collisions in your programs. Setting the collision mode to TRUE(1) will enable this debug mode, while setting it to False(0) will disable it.
FACTS:
* By default sprites have Debug collision mode disabled.
* See GetSpriteCollisionMode
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 positioned/rotated sprites to check rotated collisions against.
Part 3 The main loop, is where if checks for any collisions between sprite #1 and the other sprits have occured. If so, it prints the index of the sprite that was hit, and then continues checking until all sprites have been checked.
; ==================================== ; Part 1 - Create two coloured images ; ==================================== Cls RGB(0,0,255) GetImage 1,0,0,32,32 PrepareFXImage 1 Cls RGB(0,155,100) GetImage 2,0,0,32,32 PrepareFXImage 2 ; ============================= ; Part 2- Create some sprites ; ============================= ; Create Sprite 1, and assign it image 1 CreateSprite 1 SpriteImage 1,1 CenterSpriteHandle 1 ; Set Sprites Drawing mode to rotated SpriteDrawMode 1,2 ; Rotate this sprite 45 degree RotateSprite 1,45 ; Enable Collision for Sprite #1 SpriteCollision 1,on ; Set Sprite #1 to collision Class %0001 SpriteCollisionClass 1,%0001 ; Set Sprite #1 to collision mode to 1 (rotated) SpriteCollisionMode 1,1 ; ===================================================== ; Create a bunch of sprites to check collision against ; ===================================================== For Sprites=2 To 50 CreateSprite Sprites SpriteImage Sprites,2 CenterSpriteHandle Sprites x=Rnd(GetScreenWidth()-32) y=Rnd(GetScreenHeight()-32) PositionSprite sprites,x,y ; Set the sprites draw mode/rotation and scale SpriteDrawMode Sprites,2 RotateSprite Sprites,Rnd(360) ScaleSprite Sprites,0.5+(Rnd(100)/100.0) ; Enable Collision for this sprite SpriteCollision Sprites,on ; Set sprite to Collision Class %0010 SpriteCollisionClass Sprites,%0010 ; Set sprite to Collision mode 1 (rotated) SpriteCollisionMode Sprites,1 Next ; ============================= ; Part 3- The Main Loop ; ============================= ; Start a DO/Loop Do ; Clear the screen Cls RGB(0,0,0) ; Display a message Print "Checking For Sprite Collisions" Print "Hit Space Bar to Toggle Sprite Debug mode" ; Position the Sprite 1 at the mouses position PositionSprite 1,MouseX(),MouseY() ; Check if sprite #1 hit another sprite ; of this sprite class ThisSprite=SpriteHit(1,GetFirstSprite(),%0010) ; If there was impact, then we loop through and ; find any other sprites we might have also hit While ThisSprite>0 Print "Hit Sprite:"+Str$(ThisSprite) ; Check if this sprite hit another sprite ? NextSprite=GetNextSprite(ThisSprite) ThisSprite=SpriteHit(1,NextSprite,%0010) EndWhile If SpaceKey() Then DebugFlag=1-debugFlag ; turn all the sprites For Sprites=1 To 50 If sprites>1 Then TurnSprite Sprites,0.15 SpriteCollisionDebug Sprites,Debugflag Next ; Draw All of the sprites DrawAllSprites ; Draw the screen Sync ; Loop back to the DO statement Loop |
|