The SpriteCollisionRadius command sets the radius (size) of the circle used when the sprites collision mode is either set to circle or sliding
FACTS:
* Sprite Collision Radius is only used when the sprites collision mode is set to either Circle or Sliding mode.
* To detect impacts between circle/ellipses and sprites manually, see CircleHitSprite, EllipseHitSPritePixels
* See SpriteCollisionMode for more information about sprite collision modes.
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) Scale#=0.5+(Rnd(100)/100.0) ScaleSprite Sprites,Scale# ; Enable Collision for this sprite SpriteCollision Sprites,on ; Set sprite to Collision Class %0010 SpriteCollisionClass Sprites,%0010 ; Set sprite to Collision mode 1 (Circle) SpriteCollisionMode Sprites,2 ; Set this sprites colliion Radius SpriteCollisionRadius Sprites,16*Scale# Next DebugFlag=1 ; ============================= ; 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 |
|