Graphic and Sound
sdlBasic syntax follows the Amos/darkBasic philosophy. There are some data banks (slots), called by number, where sounds and images are stored. Multimedia files are loaded from disk to slots by a specific set of commands, sdlBasic can handle different file formats for images, sound and music. Can be loaded and stored up to 32768 images and up to 1024 sounds files. Naturally is possible to change parameters values by writing on sources but, for ordinary use, current values should be quite enough.
Specific commands allow you to play sounds stored in sound slots using computer sound card. Sounds can be played through different sound channels so several sounds may be played at the same time. You can dynamically change the maximum number of channels managed by sdlBasic for playing sounds.
sdlBasic offer two set of instructions for displaying images, that are stored in image slots, on computer monitor: they are called Sprites and Bobs. You can use up to 1024 sprites and 1024 bobs simultaneously on display. Bob and Sprites can be moved around without destroying any existing graphics on background, so they are perfect for the moving objects required by video games. Sprites and Bobs are "refreshed" (re-painted on computer monitor) each time a "screen swap" is performed. By apposite commands is possible to check collisions between sprites or between a bobs.
Sprites are completely independent from screens. If needed, they can be clipped by specific command within desired coordinates.
Bobs are very similar to sprites but, unlike them, they are relative to screens, that means that bob can't exist outside screen surface and that the bobs coordinate system is relative to its screen, so, if screen scrolls screen's bobs follow. You can decide on what screen a particular bob must operate. Bobs are perfect in program using large scrolling screens.
Display is where the graphical output is shown on computer monitor, it could be a window or the full screen. By default sdlBasic open a windows (640 x 480 pixels) with the desktop color depth. With the command setDisplay() you can change display parameters. Graphical output doesn't happen directly on display but it is executed into some virtual screens. sdlBasic allow 8 (0-7) virtual screens. A virtual screen is a sort of digital canvas where all graphic operations are executed . Screen 0 is opened by default with the display dimensions, that way it cover all the display surface. Naturally it's possible to change this parameters and to open and to close more screens. In video games it's common pratice to have a big screen for the game area and a smaller one for scores, lives etc.
Example:
screenOpen(0,640,400,0,0,640,400,0)
screenOpen(1,640,80,0,400,640,80,0)
This way screen 0 will have the size of 640x400 pixels and it will be in the upper side of display, at the same time screen 1, that will be 640x80 pixels, will be shown in the lower side of display, under screen 0.
It's possible to open screens bigger than it's visible size by writing:
Example:
screenOpen(0,6400,400,0,0,640,400,0)
The above example open a viewport on display of 640x400 pixels but the screen is ten times wider and it contine outside the visible portion.
We can make it scroll by writing following command:
Example:
offset(640,0)
so the screen will move at the x coordinate 640. Therefore, with the following routine
for i= 0 to 6400-640
offset(i,0)
screenSwap
next
This way we have a simple and efficient scrolling routine.
To switch from a screen to another, we will use the command screen(n), where n is the screen number
All graphical commands operate on the current screen, that, if not specified, is last opened.
If, for performance reasons, you want to remove support to screens, you can use command directScreen(). Naturally this choice may bring some unwanted side effects but it will speed up programs considerably, especially on older and slower PC.