Using SDL nativelyBy Chris Williams. Published: 6th Oct 2004, 09:18:10 | Permalink | Printable
Neil White makes his moveThe SDL library has helped RISC OS programmers bring various games and utilities from the open source world to the platform. Although not everything these days is about porting software: Neil White has begun using SDL in his own native puzzle games, such as Crazeeman and Conveysdl.
Neil's main reasons for using SDL for native games are that you can now play the games in the desktop, the software can use the graphics features of the SDL library and also, interestingly, the games can be ported to other platforms more easily.
We asked Neil to explain how he moved over to using SDL for his games, as Convey was originally written in BASIC and used the FastSpr library to plot graphics to the screen.
"Most of my BASIC games were always written with a view to converting them to C, so it actually only took me a few hours," explained Neil. "For example, the FastSpr routines take the x,y origin from the top left, and so does SDL. The only difference is that FastSpr defaults to plotting from the center of the image, which is quite useful sometimes. So I printed out my Convey BASIC code for easy reference and pretty much copied the code only using C functions instead of the BASIC ones.
"The main play area apart from the hoods at each end of the conveyer belt and the main character still use the same plot co-ordinates as the basic FastSpr version, and because all the collision detection is done in an array, the graphics you see on the screen are really just a representation of the game workings."
"Generally, like most of my games, Convey was a 'self improving' programming exercise. One little thing I was playing with was packing all the main
images in one file and splitting them up in the code, because keeping
all the images needed in a game as separate bitmaps in a directory could
get very silly."
One problem that Neil faced was the methods required to update the screen using SDL, which is different to how you would normally go about it with BASIC and FastSpr.
"Clearing the screen and completely redrawing the frame isn't all that efficient, so everything is plotted onto what was there before. So for example, when the score changes it plots a black rectangle before updating the score, and there is another black rectangle plotted 'under' the left edge of the belt to cover up where the character jumps into the black background. If there was a graphical background you'd have to grab the piece of background before anything moves into it and put it back after, so having a black background is a bit of a slack out."
The source code to the SDL games are also available for download, if you're feeling nosey. The Conveysdl also uses the same original data files that the BASIC version used. Neil, who also approved of Alan Buckley's SDL port of xrick, hopes to eventually cross-compile his games on his Linux PC, for speed reasons.
SDL library website
Previous: Midlands show ready for December
Next: Middleton: 'Select 32' due 2005
DiscussionViewing threaded comments | View comments unthreaded, listed by date | Skip to the end
Please login before posting a comment. Use the form on the right to do so or create a free account.
Search the archives
Today's featured article
Wakefield 2006 show report
All the thrills and spills from the weekend [Updated]
90 comments, latest by bucksboy on 23/05/06 5:57PM. Published: 15 May 2006
RISC OS in Japan
Who, where, what, when, how?
13 comments, latest by Sawadee on 14/4/05 10:01PM. Published: 4 Apr 2005
News and media:
RISCOS Ltd •
RISC OS Open •
MW Software •
Advantage Six •
CJE Micros •
Liquid Silicon •
Chris Why's Acorn/RISC OS collection •
The Register •
The Inquirer •
Apple Insider •
BBC News •
Sky News •
Google News •