Dynamic Sprite & Image Creation

Started by kevin, December 10, 2005, 03:21:52 AM

Previous topic - Next topic

kevin

This code requires PlayBasic V1.089w or above

PlayBASIC Code: [Select]
; get the screen width & height
sw=getscreenwidth()
sh=getscreenheight()

; Create an Image, 50 pixels wide by 50 pixels high
w=50
h=50
MyImage=NewImage(w,h)

; Direct PB to drawing to the newly created image
rendertoimage myimage

; draw a bunch of circles on it
for lp=0 to 10
circlec rnd(w),rnd(h),rnd(10),1,rndrgb()
next

; redirect Pb to directing to the screen
rendertoscreen


; run though and create 1 sprites that use this image a
; and randomly position them on screen
For lp=0 to 10
ThisSprite=NewSprite(rnd(sw),rnd(sh),MyImage)
if ThisSprite>0
;Get this sprites info
print getSpriteImage(ThisSprite)
print getSpriteX(ThisSprite)
print getSpriteY(ThisSprite)
endif
next

; draw all the sprites
DrawAllSprites

; display the screen for the users.
Sync
WaitKey






   -  PlayBASIC HELP - Sprite Index
   -  PlayBASIC HELP - Image Index