SpriteVisToCamera
SpriteVisToCamera SpriteNumber, CameraBits
 
Parameters:

    SpriteNumber = The Index of the sprite you wish to set the camera visibility of
    CameraBits = The camera visibility flags of this sprite
Returns: NONE
 

      SpriteVisToCamera sets the visibility of a sprite when using cameras. By default each sprite (when created) is set to be visible from within all cameras.

      To selectively limit the visibility of a sprite, you must specify which camera or cameras the sprite should appear within. You do this by combining the bit values (from the list bellow) that represent each camera.

[ Camera Bits ]

1 = Camera #1 (bit 0)
2 = Camera #2 (bit 1)
4 = Camera #3 (bit 2)
8 = Camera #4 (bit 3)
16 = Camera #5 (bit 4)
32 = Camera #6 (bit 5)
64 = Camera #7 (bit 6)
128 = Camera #8 (bit 7)
256 = Camera #9 (bit 8)
512 = Camera #10 (bit 9)
1024 = Camera #11 (bit 10)
2048 = Camera #12 (bit 11)
4096 = Camera #13 (bit 12)
8092 = Camera #14 (bit 13)
16348 = Camera #15 (bit 14)
32768 = Camera #16 (bit 15)

      For example to make a sprite visible only from camera #1 and camera #8, you'd add the values (1 + 128).





FACTS:


      * By default each sprites camrea visibilty flag is set to 65535 (%1111111111111111 in binary)




Mini Tutorial:


      This example is four main parts. Part 1 creates an image. Part 2 then creates a bunch of sprites. Part 3 creates two cameras (Camera #1 and Camera #2). Part 4 is the main program loop.



  
  
; ========================
; Part 1 - Create an image
; ========================
  
  Cls RGB(0,0,255)
  GetImage 1,0,0,32,32
  
  
; =============================
; Part 2- Create some sprites
; =============================
  
; Create a bunch fo sprites to check collision against
  For Sprites=1 To 50
     CreateSprite Sprites
     SpriteImage Sprites,1
     x=Rnd(GetScreenWidth()-32)
     y=Rnd(GetScreenHeight()-32)
     PositionSprite sprites,x,y
  Next
  
  
; =============================
; Part 3- Create 2 cameras
; =============================
  w=GetScreenWidth()
  h=GetScreenHeight()
  
; Create Camera 1
  CreateCamera 1
; Set camera #1 viewport area to the left
; side of the screen
  CameraViewPort 1,1,1,(w/2)-1,h-1
  
; Set camera #2 viewport area to the right
; side of the screen
  CreateCamera 2
  CameraViewPort 2,(w/2)+1,1,w-1,h-1
  
  
; =============================
; Part 4- The Main Loop
; =============================
  
;Create a variable that we'll use to set what
;camera(s) the created sprites are visible within
  CameraVisibleFlag=%011
  
; Start a DO/Loop
  Do
   ; Clear the Screen to a bluey colour
     Cls RGB(100,100,200)
     
   ; Tell PB to capture the following draw commands to the
   ; scene buffer, rather than draw them
     CaptureToScene
     ClsScene
     
   ; Check if the SpaceKey is pressed
     If SpaceKey()=true
        
      ; Change the camera visibility variable
        Inc CameraVisibleFlag
        
      ; Limit the CameraVisibleFlag value to 3,
      ; if it goes over then reset it to zero
        If CameraVisibleFlag>3 Then CameraVisibleFlag=0
        
      ; Loop through all the sprites and set
      ; theire camera visiblity value
        ThisSprite=GetFirstSprite()
        While ThisSprite>0
           SpriteVisToCamera ThisSprite,CameraVisibleFlag
           ThisSprite=GetNextSprite(ThisSprite)
        EndWhile
        
        WaitNoKey
     EndIf
     
   ; Draw All of the sprites to the SCENE buffer
     DrawAllSprites
     
   ; Render the created cameras
     DrawAllCameras
     
     
   ; Display a messages over the Cameras
     SetCursor 0,0
     w=GetScreenWidth()/2
     CenterText w,10,"Sprite Visible To Camera"
     CenterText w,30,"Space to Toggle The Sprite Camera Settings"
     s$=Right$(Bin$(CameraVisibleFlag),2)
     CenterText w,50,"Current Camera Vis Setting:%"+s$
     
   ; Draw the screen
     Sync
   ; Loop back to the DO statement
  Loop
  




This example would output.

  
  no Text Output
  

 
Related Info: CreateCamera | GetSpriteVisToCamera :
 


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