QuadHitSpritePixels
CollisionState = QuadHitSpritePixels(X1, Y1, X2, Y2, X3, Y3, X4, Y4, SpriteIndex, Accuracy#)
 
Parameters:

    X1 = The X1 coordinate of the quad
    Y1 = The Y1 coordinate of the quad
    X2 = The X2 coordinate of the quad
    Y2 = The Y2 coordinate of the quad
    X3 = The Y3 coordinate of the quad
    Y3 = The Y3 coordinate of the quad
    X4 = The X4 coordinate of the quad
    Y4 = The Y4 coordinate of the quad
    SpriteIndex = The Sprite to check for collision against
    Accuracy# = The level of accuracy that should be used.
Returns:

    CollisionState = The result of the collision query (0= No collision ,1 = Collision)
 

      The QuadHitSpritePixels function detects if a collision occurs between a Quad sided convex polygon and any pixel within the sprite.


Example Accuracy Values
      0.25 = Reduce collision accuracy to 25%
      0.50 = Reduce collision accuracy to 50%
      0.75 = Reduce collision accuracy to 75%
      1.00 = Set collision accuracy to 100%
      2.00 = Set collision accuracy to 200%




FACTS:


      * The Accuracy parameter allows the user to fine tune the quality of the pixel level sprite collisions. Generally speaking the lower the quality the faster the comparison. On the flip side the higher the quality the more accurate, but slower the comparison. It's up to the user to choose an accuracy level that is appropriate for your images and the performance of your game.

      * Pixels level collisions ignore the sprites transparent colour.

      * Also see SpriteCollisionMode





Mini Tutorial:


      This example creates a random image, creates 10 randomly positioned sprites on the screen using this image. The main loop rotates the sprites while scans them for collisions using QuadHitSpritePixels

  
  
; clear the screen to black
  Cls RGB(0,0,0)
  
  
; Make an image with circles on it
  For lp =0 To 25
     CircleC Rnd(100),Rnd(100),RndRange(2,10),1,RndRGB()
  Next
  GetImage 1,0,0,100,100
  PrepareFXImage 1
  
  
; Make 10 sprites
  For spr=1 To 10
     
   ; postion the spriote randomly on the screen
     x=Rnd(GetScreenWidth())
     y=Rnd(GetScreenHeight())
     
   ; Create the sprite using image #1
     Spr=NewSprite(x,y,1)
     
   ; center the sprite
     CenterSpriteHandle spr
     
  Next
  
  
  
  Do
     Cls RGB(0,0,0)
     
   ; Check if the mouse  is over a sprite
     x1#=MouseX()
     y1#=MouseY()
     
     x2#=x1#+150
     y2#=y1#+20
     x3#=x1#+100
     y3#=y1#+70
     
     x4#=x1#-300
     y4#=y1#+70
     
   ; Draw the test triangle
     QuadC x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#,RGB(255,255,255)
     
   ; start for/next loop from 1 to 10
     For spr=1 To 10
        
      ; Turn this sprite
        TurnSprite spr,0.25
        
      ; Check if our test triangle hits any pixels in this sprite
        If QuadHitSpritePixels(x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#,spr,1)=true
         ; Flash the sprite if there's a collison
           SpriteDrawMode Spr,2+4096
        Else
         ; Set it's draw mode to just rotated
           SpriteDrawMode Spr,2
        EndIf
     Next
     
     DrawAllSprites
     
     Sync
  Loop
  





 
Related Info: CircleHitSprite | EllipseHitSpritePixels | PointHitSprite | PointHitSpritePixels | QuadHitSprite | RayHitSprite | RectHitSprite | RectHitSpritePixels | ShapeHitSprite | SpriteCollisionMode | SpriteHit | SpritesOverlap | TriangleHitSpritePixels :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com