SpriteInCamera
Flag = SpriteInCamera(SpriteIndex, CameraIndex)
 
Parameters:

    SpriteIndex = The Index of the sprite you wish to query
    CameraIndex = The Index of the camera you wish to check this sprite against
Returns:

    Flag = The state of this sprite (0= outside of camera, 1 = inside of camera)
 

      The SpriteInCamera functions check if a sprite position is within the viewport of a camera.



FACTS:


      * This compares the world space position of the sprite to the camera.

      * See CameraBasics, CreateCamera



Mini Tutorial:


      This example is really 4 parts. Part1 creates an image. Part 2 creates some randomly positioned sprites using the previous created image. Part 3 Creates a camera, while Part 4 is the main process loop, which lets the user control the camera, and thus displaying the (SpriteinCamera) status of each sprite.


  
; ========================
; Part 1 - Create an image
; ========================
  
  Cls RGB(0,255,255)
  GetImage 1,0,0,32,32
  
  
; =============================
; Part 2- Create some sprites
; =============================
  
; Create a bunch of randomly positioned sprites
  For Sprites=1 To 10
     CreateSprite Sprites
     SpriteImage Sprites,1
   ; Randomly position them
     PositionSprite sprites,Rnd(1000),Rnd(1000)
  Next
  
  
  
; =============================
; Part 3- Create a camera
; =============================
  
  CreateCamera 1
  w=GetScreenWidth()-32
  h=GetScreenHeight()-32
  CameraViewPort 1,32,32,w,h
  
  
; =============================
; Part 4- The Main Loop
; =============================
  
  MakeBitmapFont 1,RGB(255,255,255)
  
; Start a DO/Loop
  Do
   ; Clear the screen
     Cls RGB(0,0,255)
     
   ; Tell PB to capture all future GFX commands
   ; to the scene buffer, rather than draw them
     CaptureToScene
     
   ; Clear the scene buffer
     ClsScene
     
   ; Controls for moving the camera
     If UpKey() Then MoveCamera 1,0,-5
     If DownKey() Then MoveCamera 1,0,5
     If LeftKey() Then MoveCamera 1,-5,0
     If RightKey() Then MoveCamera 1,5,0
     
   ; Draw All of the sprites to scene buffer
     DrawAllSprites
     
   ; Draw the Camera
     DrawCamera 1
     
   ; Cycle through the sprites and display if their
   ; in view of the camera Or Not
     
     For Sprites=1 To 10
        s$="Sprite "+Str$(Sprites)+" is in camera:"
        If SpriteInCamera(Sprites,1)=true
           s$=s$+"Yes"
        Else
           s$=s$+"No"
        EndIf
        Print s$
     Next
     
   ; Draw the screen
     Sync
     
   ; Loop back to the DO statement
  Loop
  




This example would output.

  
  
  

 
Related Info: CameraBasics | CreateCamera | RectHitSprite | RectHitSpritePixels | SpriteInRegion | TriangleHitSpritePixels :
 


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