(Updated 5 Jan 2005.)
Here are some key changes you should be aware of from previous versions of Blitz.
Graphics
Graphics now has different parameters: width, height, depth and refresh rate.
If you're trying to port an existing program that uses the last 'window mode' parameter, you'll probably find that your game runs at a crawl. This is because BlitzMax defaults to locking game update speed to that of the display refresh rate. If you've passed 1, 2 or 3 as the last parameter of Graphics, your game will be updating at 1, 2 or 3 Hz respectively! Just delete the last parameter.
Images
Because BlitzMax's 2D engine (Max2D) now renders images using OpenGL (allowing drawing to be accelerated using 3D hardware), you can now carry out operations such as scaling, rotation and alpha blending of images (ie. making them see-through) in real time.
Unlike previous Blitzes, you don't set the rotation, scale or alpha level of individual images, but instead call SetRotation, SetScale and SetAlpha, which will affect all drawing operations until you call them again with different values.
This means that if you call SetScale 0.5, 0.5, all images will be drawn at half their normal width and height until you revert back to normal scaling with SetScale 1, 1, and may mean calling these commands before drawing individual images if they are to be drawn with different values. This is how OpenGL works internally, so is very fast.
Images are also affected by SetColor, allowing images to be 'tinted'. The red, green and blue values in an image are affected by the percentage of red, green and blue values you specify with SetColor, so 255, 255, 255 gives 100% for each of the red, green and blue values in an image, meaning it will be drawn normally; SetColor 127, 127, 127 would give (approximately) 50% of each value, effectively making the image half as bright, SetColor 0, 255, 255 would take away all of the red component in an image, and SetColor 255, 0, 0 would leave only the red component, effectively tinting the image red.
If you've called SetColor with anything other than 255, 255, 255, and then want to draw your images normally, call SetColor 255, 255, 255 before doing so. You'll probably notice you need this when your images start to flash unexpectedly in different colours!
KeyDown/KeyHit
BlitzMax now features a set of pre-defined keycode constants with different numerical values to previous Blitzes. See the Key Codes section of the documentation (under Module Reference) for details. In particular, if you use the common "Repeat [... ] Until KeyHit (1)" to detect the Esc key, change it to KeyHit (KEY_ESCAPE). The value 1 now relates to a left mouse button press, so don't wear out your Esc key in confusion and frustration...
Lists
Blitz 'type' objects were previously added automatically to a single list per type. This is no longer the case. Because BlitzMax allows multiple lists per type, you must create the list manually. Fortunately, this is as easy as:
Note that the list variable mylist is created as type TList, an internal BlitzMax type. You add objects to this list using the ListAddLast command (the example below assumes a type called 'Example' has been created):
Instead of iterating through lists using the For... Each construct, use the new For... EachIn construct:
Syntax
Variable types are now declared using the : symbol, not the . symbol:
Type field access now uses the . character instead of the \ character:
The core variable types use the same shortcut symbols as before (only available for the most common types), with the addition of ! for double-precision (64-bit) floating point variables; you can also use their names if you prefer:
Labels
Labels are now defined using the # character:
Data
Data sections are now accessed via DefData, RestoreData and ReadData. Note the use of the new label syntax again:
Feel free to post your own discoveries, and try not to get too upset about the changes. You may well trip up for a while, but you'll soon get the hang of it!
Here are some key changes you should be aware of from previous versions of Blitz.
Graphics
Graphics now has different parameters: width, height, depth and refresh rate.
If you're trying to port an existing program that uses the last 'window mode' parameter, you'll probably find that your game runs at a crawl. This is because BlitzMax defaults to locking game update speed to that of the display refresh rate. If you've passed 1, 2 or 3 as the last parameter of Graphics, your game will be updating at 1, 2 or 3 Hz respectively! Just delete the last parameter.
Images
Because BlitzMax's 2D engine (Max2D) now renders images using OpenGL (allowing drawing to be accelerated using 3D hardware), you can now carry out operations such as scaling, rotation and alpha blending of images (ie. making them see-through) in real time.
Unlike previous Blitzes, you don't set the rotation, scale or alpha level of individual images, but instead call SetRotation, SetScale and SetAlpha, which will affect all drawing operations until you call them again with different values.
This means that if you call SetScale 0.5, 0.5, all images will be drawn at half their normal width and height until you revert back to normal scaling with SetScale 1, 1, and may mean calling these commands before drawing individual images if they are to be drawn with different values. This is how OpenGL works internally, so is very fast.
Images are also affected by SetColor, allowing images to be 'tinted'. The red, green and blue values in an image are affected by the percentage of red, green and blue values you specify with SetColor, so 255, 255, 255 gives 100% for each of the red, green and blue values in an image, meaning it will be drawn normally; SetColor 127, 127, 127 would give (approximately) 50% of each value, effectively making the image half as bright, SetColor 0, 255, 255 would take away all of the red component in an image, and SetColor 255, 0, 0 would leave only the red component, effectively tinting the image red.
If you've called SetColor with anything other than 255, 255, 255, and then want to draw your images normally, call SetColor 255, 255, 255 before doing so. You'll probably notice you need this when your images start to flash unexpectedly in different colours!
KeyDown/KeyHit
BlitzMax now features a set of pre-defined keycode constants with different numerical values to previous Blitzes. See the Key Codes section of the documentation (under Module Reference) for details. In particular, if you use the common "Repeat [... ] Until KeyHit (1)" to detect the Esc key, change it to KeyHit (KEY_ESCAPE). The value 1 now relates to a left mouse button press, so don't wear out your Esc key in confusion and frustration...
Lists
Blitz 'type' objects were previously added automatically to a single list per type. This is no longer the case. Because BlitzMax allows multiple lists per type, you must create the list manually. Fortunately, this is as easy as:
mylist:TList = CreateList ()
Note that the list variable mylist is created as type TList, an internal BlitzMax type. You add objects to this list using the ListAddLast command (the example below assumes a type called 'Example' has been created):
myobject:Example = New Example ListAddLast mylist, myobject
Instead of iterating through lists using the For... Each construct, use the new For... EachIn construct:
For e:Example = EachIn mylist Print e.blah Next
Syntax
Variable types are now declared using the : symbol, not the . symbol:
' Old version: p.Player = New Player ' New version: p:Player = New Player
Type field access now uses the . character instead of the \ character:
Type Oink Field x End Type o:Oink = New Oink o.x = 1 Print o.x
The core variable types use the same shortcut symbols as before (only available for the most common types), with the addition of ! for double-precision (64-bit) floating point variables; you can also use their names if you prefer:
' Integers: i = 5 ' First reference to a variable assumes integer if nothing specified... i% = 5 i:Int = 5 ' Floats: f# = 5.0 ' (Tip for UK Mac users: The # character is obtained via Alt + 3!) f:Float = 5.0 ' Strings: s$ = "Oink" s:String = "Oink" ' Bytes: b:Byte = 1 ' Shorts: s:Short = 10 ' Doubles: d! = 10000 d:Double = 10000
Labels
Labels are now defined using the # character:
#mylabel If a = 1 Then Goto mylabel
Data
Data sections are now accessed via DefData, RestoreData and ReadData. Note the use of the new label syntax again:
RestoreData mydata For a = 1 To 5 ReadData info Print info Next #mydata DefData 2, 4, 6, 8, 10
Feel free to post your own discoveries, and try not to get too upset about the changes. You may well trip up for a while, but you'll soon get the hang of it!