width - width of the new image (or its frames)
height - height of the new image frames - optional number of frames (assumed to be a single frame) flags - optional image flags |
Sometimes you want to create a completely new graphic on the fly (using other images, drawing commands, etc.) instead of loading one. This command will let you create a new image with a single frame or multiple frames for animation. You specify the width, height, and optional number of frames. The example should be pretty self-explainatory.
The optional flags parameter can be one of: 1 : managed (image is frequently drawn but seldom modified - this is the default) 2 : dynamic (image is frequently drawn and modified) 4 : scratch (image is seldom drawn or modified) Managed images are the default. Dynamic images are the fastest, but can be 'lost' when the display mode changes. This means the contents of the image will be scrambled, and you will need to restore the image content. If you are frequently redrawing the image contents, this isn't really a problem. If not, you should use managed images! Scratch images are slow all round but consume no videomemory. These are good for things like title pages and 'temporary work' images. Note that canvas buffers and back buffers should be considered 'dynamic'. See also: LoadImage, DrawImage, SaveImage, Graphics. |
; CreateImage/TileImage/ImageBuffer example
; Again, we'll use globals even tho we don't need them here ; One variable for the graphic we'll create, one for a timer Global gfxStarfield, tmrScreen ; Declare graphic mode Graphics 640,480,16 ; Create a blank image that is 32 pixels wide and 32 high with 10 frames of 32x32 gfxStarfield=CreateImage(32,32,10) ; loop through each frame of the graphic we just made For t = 0 To 9 ; Set the drawing buffer to the graphic frame so we can write on it SetBuffer ImageBuffer(gfxStarfield,t) ; put 50 stars in the frame at random locations For y = 1 To 50 Plot Rnd(32),Rnd(32) Next Next ; Double buffer mode for smooth screen drawing SetBuffer BackBuffer() ; Loop until ESC is pressed While Not KeyHit(1) ; Only update the screen every 300 milliseconds. Change 300 for faster or ; slower screen updates If MilliSecs() > tmrScreen+300 Then Cls ; clear the screen ; Tile the screen with a random frame from our new graphic starting at ; x=0 and y=0 location. TileImage gfxStarfield,0,0,Rnd(9) Flip ; Flip the screen into view tmrScreen=MilliSecs() ; reset the time End If Wend |