Wave's~ BlitzMax Tutorial for NG | ~ November, 2015 ~ Version 11
Beginners guide to BlitzMax |
Sample Program
Note: If windowed mode fails to work (800,80,0) then use standard mode (800,600).
Strict Local X Graphics 800,80,0 Repeat DrawRect X,40,10,12 DrawText "- please wait -",0,0 X:+2 Flip Until x >= 800 | 'Declare x variable 'Smaller Window Size 'Top of the Repeat-Until loop '40 = y coordinate, 10px = rect width, 12px = rect height 'text string inside "" and 0,0 = screen location (top left) 'increase x with 2 every loop 'show what you have drawn 'Exit the loop when X is greater or equal to 800
Press f5 to build and run the example. The above code will create a "loading line" on the screen. if you put a Cls on a new line below Flip , you'll notice that a instead of a line, a box will be traveling from 0 to 800, measured in pixels. You may also replace DrawRect with DrawOval and guess what...
flip and clear
In BlitzMax everything you draw is drawn to an invisible board. You can draw all you want to this board but it won't show up on screen. You can see it as if blitzmax is drawing on the back of your screen, then when you want to show it, you flip the board and we can see what has been drawn to it. if we keep drawing a lot of stuff and flip, then continue drawing a lot of stuff, the board will be a mess. this is why we clear the board after we have flipped it, but this also means we have to redraw everything we previously had on the board! That's how it works. This board is known as the back buffer. you do not need to (and cannot) set the back buffer as in blitz3d/blitzplus. This method with flip and clear is called double buffering and is done to prevent flickering graphics.
How to make our loading bar work while using cls? (remove cls to see what happens)
Strict Local W Graphics 800,600,0 Repeat Cls Drawrect 0,40,W, 12 drawtext "- please wait -" ,0,0 drawtext " width = "+W ,0,20 W:+3 Flip Until W >= 800 | 'set graphics mode 'let's change the width of the box instead
The coordinate System
This part is identical to BlitzBasic. At the Top Left of the screen we have the point 0,0. Add these lines to the above example, just one row below "Repeat": (They might be hard to see, try full-screen by removing the last ",0" in graphics )
Plot 0,0 Plot 400,40 | 'Draws a pixel in the top left corner. Try 1,1 too 'Draws a pixel at location 400,40 Read: plot at X:400, Y:40
The X-Axis is the Horizontal Axis from the left side of the screen to the right side, The Y-Axis is Vertical and travels from the Top to the bottom. The resolution is what determines how many pixels you will have at each axis. So in our example the screen width (in pixels) would be 800 and the screen height 600. The more pixels at screen the more calculations is required by the computer both in 2D and 3D. You can get the current screen width with GraphicsWidth()The Line X1,Y1,X2,Y2 command creates a line from X1,Y1 to X2,Y2.
Add the following to our example:
DrawLine 40,40,80,80 DrawLine 40,40,40,20
To Index | Next Page | page 6