;--------------------------------------------------------------------- ; SpriteInRegion Example ;--------------------------------------------------------------------- ; ================================================================ ; First Create an image with Shaded Circle pattern on it ; ================================================================ Small_Circle_Image=CreateCircleImage(75) ; ================================================================= ; Create 50 sprites and randomly position them around the screen ; ================================================================= NumberOfSprites=50 For ThisSprite=1 To NumberOfSprites ;CReate this sprite CreateSprite ThisSprite ; Set sprite to Automatically center it's image around the sprites axis. AutoCenterSpriteHandle ThisSprite,true ; Assigned This Sprite An IMage SpriteImage ThisSprite,Small_Circle_Image ; Set sprite to rotated draw mode so we can use Tint also SpriteDrawMode ThisSprite,2 ; Randomly position this sprite within the screen PositionSprite ThisSprite,Rnd(GetScreenWidth()),Rnd(GetScreenHeight()) Next ; Tell PB to limit speed of the program to 60 Frames (updates) per second or bellow SetFPS 60 ; Start out update loop Do ; Clear the Screen to back 0= rgb(0,0,0) Cls RGB(25,30,45) ; Tell PB to render All the Sprites now. DrawAllSprites ; Read the Mouse Position mx=MouseX() my=MouseY() ; Create a box 100y 100 pixel from the mouse position box_x1=mx box_y1=my box_x2=mx+100 box_y2=my+100 Box box_x1,box_y1,box_x2,box_y2,false ; Run Through Sprite Checking if any of them are with For ThisSprite=1 To NumberOfSprites ThisColour=RGB(255,255,255) ; Check if This sprite is within this region If SpriteInRegion(ThisSprite,box_x1,box_y1,box_x2,Box_y2)=true ; Draw a Circle at the sprites Axis point if it IS completely/[partly ;inside the region CircleC GetSpriteX(thissprite),GetSpriteY(thissprite),5,1,$ff ThisColour=RndRGB() EndIf SpriteTint ThisSprite,ThisColour Next ; Display a message Ink $ffffff Print "Checking Sprites In Region" ; Display the screen and loop back to the DO statement to continue the loop Sync Loop ; ========================================================= ; Create an Image with a shaded circle pattern on it. ; ========================================================= Function CreateCircleImage(Size) ThisImage=NewFXImage(Size,Size) RenderPhongImage ThisIMage,size/2,size/2,RGB(128+Rnd(127),128+Rnd(127),128+Rnd(127)),200,255.0/(size/1.5) EndFunction ThisImag |