The PointOverCamera function returns if a point is over a cameras viewport.
FACTS:
* The camera is assumed to be attached to the screen, If it's attached to an image you'll have to adjust your test point accordingly
Mini Tutorial:
This example creates two cameras, then uses PointOverCamera to check and highlight what camera the mouse pointer is currently over.
sw=GetScreenWidth() sh=GetScreenHeight() ; =========================== ; Part 1 Create Camera #1 ; =========================== ; Create Camera 1. CreateCamera 1 ; Activate the camera Auto CLS CameraCls 1,on ; Set the Cameras Auto CLS colour CameraClsColour 1,RGB(100,155,0) ; Set Camera #1 to be the left size of teh screen CameraViewPort 1,0,0,(sw/2)-1,sh ; =========================== ; Part 2 Create Camera #2 ; =========================== ; Create Camera 2. CreateCamera 2 ; Activate the camera Auto CLS. CameraCls 2,on ; Set the Cameras Auto CLS colour CameraClsColour 2,RGB(00,55,100) ; Set Camera #1 to be the left size of teh screen CameraViewPort 2,(sw/2)-1,0,sw,sh ; =========================== ; Part 3 ; =========================== ; Start a Do /loop Do ; Tell PB to caputre all GFX commands to the Scene buffer CaptureToScene ; Clear the scene buffer ClsScene ; DRaw some random Circles to the screen buffer For lp =0 To 100 CircleC Rnd(200),Rnd(200),Rnd(10),Rnd(1),RndRGB() Next ; Draw All cameras DrawAllCameras ; Display message SetCursor 0,0 Print "Point Over Camera Example" ; Read the mouses position as test point mx#=MouseX() my#=MouseY() ; Start a For/Next Loop For lp=1 To 2 ; Check if point is over this camera index If PointOverCamera(lp,mx#,my#)=true ; Point is opver camera, so get it's viewport] ; position & width/height x=GetCameraViewPortX1(lp) y=GetCameraViewPortY1(lp) w=GetCameraWidth(lp) h=GetCameraHeight(lp) ; Draw a highlight box BoxC x,y,x+(w-1),y+(h-9),0,RGB(255,255,255) ; Render text over this camera CenterText x+(w/2),y+(h/2),"Point Over This Camera" EndIf Next ; Show the user the screen. Sync ; Loop back to the DO statement Loop |
This example would output.
|