;---------------------------------------------------- ; DrawSprite Example ;---------------------------------------------------- ; ========================================================= ; First Create an Image, with a random circle pattern on it. ; ========================================================= Size=95 circle_image=CreateCircleImage(Size) ; ========================================================= ; Create 10 sprites ; ======================================================== NumberOfSprites=10 For ThisSprite=1 To NumberOfSprites ;Create this sprite CreateSprite ThisSprite ; Set this sprite auto center it's handle on any image AutoCenterSpriteHandle ThisSprite,true ; Set each Sprite to use our circle image for ; it's artwork to display. SpriteImage ThisSprite,Circle_Image ; Randomly position this sprite within the screen Xpos=Rnd(GetScreenWidth()) Ypos=Rnd(GetScreenHeight()) PositionSprite ThisSprite,Xpos,Ypos Next ; Tell PB to limit speed of the program to 30 Frames ; (updates) per second or bellow SetFPS 30 ; Start of Main Do/Loop Do ; Clear the Screen to back 0= rgb(0,0,0) Cls RGB(0,0,0) ; Manually run through our created sprites and render ; each of them. For lp =1 To NumberOfSprites ; Draw this sprite DrawSprite lp ;Display the sprite index over it ShowText(GetSpriteX(lp),GetSpriteY(lp),"sprite:"+Str$(lp)) Next ; Display a message in green Ink RGB(0,255,0) Print "Manually Rendering Sprites" Print "===========================" ; 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=NewImage(size,size) Colour=RGB(128+Rnd(127),128+Rnd(127),128+Rnd(127)) RenderPhongImage ThisIMage,size/2,size/2,Colour,200,255.0/(size/2) EndFunction ThisImage Function ShowText(x,y,s$) ;Display the sprite index over it Ink 0 CenterText x-1,y-1,s$ Ink RGB (255,255,255) CenterText X,Y,s$ EndFunction |