( Brutus2D 1.4.x, 1.5.x, 1.6, 1.7 )
graphics.Initialize - start the Graphics object
|
Table of Contents
|
Description
graphics.Initialize width, height, windowed, colorDepth
- width - width of window/horizontal resolution of screen
- height - height of window/vertical resolution of screen
- windowed - windowed/fullscreen as true or false
- colorDepth - color depth, 32,24,16, or 8
graphics.Initialize starts the graphics object so that you can use other graphics commands. Since Brutus2D is a 2D game programming language, it is essentially useless without the graphics object. You should call graphics.Initialize first, before you do anything else.
Examples
Example of Use
To make your game functional (ie, not seize up when started) you also need to include graphics.Clear and graphics.Display. Also, to make sure that the graphics object shuts itself off when your game exits, make sure to use graphics.Terminate before you end the game.
By default, graphics.Initialize opens a 640x480 window.
'press escape to exit
graphics.Initialize
key.Initialize
Do While Not key.Pressed( vk_escape ) And Not keyPressed( vk_windowx )
graphics.Clear
'draw some stuff
graphics.Display
Loop
graphics.Terminate
key.Terminate
Window Size
If you're not happy with the 640x680 window, you can change it to any size. The first argument graphics.Initializeaccepts is the width of the window, the second one is the height of the window.
graphics.Initialize [width], [height]
'press escape to exit
graphics.Initialize 800, 600
key.Initialize
Do While Not key.Pressed( vk_escape ) And Not key.Pressed( vk_windowx )
graphics.Clear
'draw some stuff
graphics.Display
Loop
graphics.Terminate
key.Terminate
You'll notice that the code in this example is exactly the same as the example above except that graphics.Initialize has been used to create an 800x600 window.
Full Screen
If you want your game to be full screen, you need to make sure that you set the width and height to a resolution that most computers use. The most common resolutions are 320x240 (used for most 2D games), 640x480, 800x600, and 1024x768. If you do not use a resolution supported by your player's computer, graphics.Initialize will run the game in a window rather than full screen.
'press escape to exit
graphics.Initialize 800, 600, false
key.Initialize
Do While Not key.Pressed( vk_escape ) And Not key.Pressed( vk_windowx )
graphics.Clear
'draw some stuff
graphics.Display
Loop
graphics.Terminate
key.Terminate
Note: Before you try this example, remember you can exit by pressing the escape key.
The code in this example is the same to the one above, except that a third argument has been included, false to tell Brutus2D that you do not want the game to run in a window.
Useful Info
- When running in full screen, Brutus will not update the screen faster then the refresh rate of the monitor
Related Pages
- graphics.Clear - clear the current frame.
- graphics.Display - draw the current frame.
- graphics.Terminate - terminate the graphics object.
- console.Initialize - use a text mode instead.