;--------------------------------------------------------------------- ; CentreSpriteHandle Example ;--------------------------------------------------------------------- ; ========================================================= ; First Create an Image with a random circle pattern on it. ; ========================================================= Size=95 Circle_Image=NewImage(Size,Size) RenderToImage Circle_Image Randomize 47 For lp=size/2 To 1 Step -1 CircleC Size/2,Size/2,lp,1,RndRGB() Next RenderToScreen ; ========================================================= ; Create 5 sprites ; ======================================================== NumberOfSprites=5 For ThisSprite=1 To NumberOfSprites ;CReate this sprite CreateSprite ThisSprite ; Set each Sprite to use our circle image for it's artwork to display. SpriteImage ThisSprite,Circle_Image ; Randomly Centre a sprites handle for it's newly assigned image. If Rnd(1)=0 CenterSpriteHandle ThisSprite EndIf ; Randomly position this sprite within the screen PositionSprite ThisSprite,Rnd(GetScreenWidth()-size),Rnd(GetScreenHeight()-size) Next ; Tell PB to limit speed of the program to 30 Frames (updates) per second or bellow SetFPS 30 ; Start out update loop Do ; Clear the Screen to black rgb(0,0,0)=black Cls RGB(0,0,0) ; Display a message Ink $ff00 Print "Render Sprites Manually and display the effects of handles" Print "===========================================================" ; Manually run through our created sprites and render them. Displaying the sprites ; POSITION and it's For lp =1 To NumberOfSprites ; DRaw this sprite DrawSprite lp ;Display a bound box around where sprite POSITION and image would be ; normally be.. Ink RGB(0,255,0) w=GetSpriteWidth(lp) h=GetSpriteWidth(lp) x=GetSpriteX(lp) y=GetSpriteY(lp) Line x,y,x+w,Y Line x+w,y,x+w,Y+h Line x+w,y+h,x,Y+h Line x,y,x,Y+h Circle x,y,5,1 Text x,y,"Sprite Axis:"+Str$(lp) ; Get Sprites Handle offset Hx=GetSpriteHandleX(lp) Hy=GetSpriteHandleY(lp) ; Display a bounding box around where the sprites image is drawn after applying ; the sprites handle offset.. x=x+hx y=y+hy Ink RGB (255,255,255) Line x,y,x+w,Y Line x+w,y,x+w,Y+h Line x+w,y+h,x,Y+h Line x,y,x,Y+h Text x,y,"Sprite Handle: x:"+Str$(hx)+" y:"+Str$(hy) Next ; Display the screen and loop back to the DO statement to continue the loop Sync Loop |