Wave's~ BlitzMax Tutorial~ July 20, 2005 ~ Version 10
Beginners guide to BlitzMaxversion 7

Images
Images are a fast and easy way to draw graphics to the screen. Before you find or create an image, make sure you know your imagename and your background color in red, green and blue.
 
To follow this section I recommend you open you favorite drawing program and make an image, like 50x50 pixels. Load and Draw it, set its Alpha and MaskColor. Test your way through.
 
Maskcolor is the color you want to use as the transparent color. If black are your mask color all black pixels in your image will be transparent.
 
SetMaskColor 0,0,0 'Black is the default anyway
Global My_Image:Timage=LoadImage( "ImageName.bmp" )
It is recommended to load images into Timage objects because that way BMax can help you clean up the memory when the image are no longer being used.
 
Loadimage returns an image-object. This is what blitz uses to keep track of all your loaded images. You use this object which points to the address of this image when you want to draw or edit an image. Loadimage has to come after you initiate your graphics. Otherwise your images will be plain white or you'll receive a runtime error.
MidHandleImage( My_image ) ' Centers the image's coordinates.
 
'You can also use:
Automidhandle(true) 'which centers all images.
 
' These commands alter how an image is drawn.
' Set them before you draw an image to make it take effect.
Setcolor(red,green,blue): 'Changes the color of your image
' White which is 255,255,255 = nocolor change.
SetAlpha( Alpha# ) 'Set the transparency of the image. 1 solid, 0 invisible, 0.5 half-cloaked.
 
' To display the transparency effect you need to
SetBlend( AlphaBlend )
SetRotation( Direction ) 'rotates the image in real-time! No need to ever pre-rotate images.
 
' This command considers 0 rotation to be to the right.
 
' If your image is not already rotated to the right add
SetRotation(direction + offset) 'where offset is 90 if the original image points up.
' 180 if to left, -90 if down.
 
' This does depend on your game. If you use movement in 2D
' with Cos/Sin you need dir=0 to be to the left as that's the
' nature of Cos/Sin. Otherwise it shouldn't matter much.
 
SetScale(Scale#) ' Scale the image in real-time too.
'1 = 100%, 2 = 200%, 0.5 = 50% of original size.
 
' Now you can draw your image with:
Drawimage( My_image )

If you want to alter an image fast in real-time then you need to use pixmaps or convert the image you have to a pixmap. Like if you want to change the maskcolor after load.

Real-Time Timers
Timers that that does not stop your game. They are used when you need timing in your game. Let's say you want an action to take place after 10seconds. To get the current time you'll use millisecs() which will give you the CPU-Clock in milliseconds. Millisecs() returns an Int and it is increased every millisecond.

This is a simple way to time an event:
Strict
Local EndTime,SecTime,Secs
 
EndTime = MilliSecs() + 8000 'Set "EndTime" to current time + 8 seconds
 
Repeat
If SecTime < MilliSecs()
Print Secs+" seconds passed"
Secs:+1
SecTime = MilliSecs() + 1000
EndIf
'If the current time is greater than EndTime then End
If MilliSecs() > EndTime Print "8 seconds...Exit" ; End
Forever
 
To Index | Next Page page 19