by Andy Partington / Kung-Fu Coders(tm)
Yes welcome! This tutorial is my first contribution to the Yaroze scene, to try and help other learner Yaroze-heads like me to sort things out. I've just sussed out how to do backgrounds (using the GsSortFixBg16()-type functions and all the rest of it), so I thought i'd SHARE the WEALTH... Hope it does somebody some good!
Any comments? Drop me some email (term-time only!) at:
a.partington@lancaster.ac.uk
OK, you probably know what a background is and where to use it, but i'll cover it because its a tutorial, innit?
A background consists of a grid of blocks of a certain size (16*16 pixels in this case), the positions and type of which are defined by some map data.
The very first thing you will need is your graphics. Load your chosen graphics package, then draw a grid of 16*16 squares. These squares are to be the building blocks of your background, so draw something cool inside each of them. For this example, I am using 4 blocks across and 4 blocks down (meaning the size of the entire thing is 64*64), giving 16 blocks to play with. You can have more, but I couldn't be arsed drawing them all.
Now you have some smart-looking blocks, you'll want to do something with them. To use the background handling facilities you will need:
Your graphics will be stored here.
This structure is responsible for controlling your background. The most important things are the attribute, scroll values, and the pointer to a GsMAP structure (more on that in a bit). Check p36 of the library reference guide for more info. At first glance, you think "Buzzin! You can rotate and zoom these in and out sort of like Mode 7 on the SNES!". Sadly, no. As far as I know (and I don't know that much) the standard Yaroze libraries don't support the scaling and rotation functions for backgrounds, even though the GsBG structure implies that it can be done :( Dead nice, that. Still, there's nothing stopping you from coding your own background handler...
This is a structure that links the GsBG and GsCELL structures. It contains variables for setting the width and height of your blocks (but no matter what you put in, it will be ignored!), the size of your background (in 16*16 blocks), and it also contains pointers to your map data and to the GsCELL structures.
For each 16*16 block that you have for your backgrounds, a GsCELL structure should be created. This gives the X and Y offsets of each block in the graphics you have drawn, amongst other things. It also specifies which blocks should be mirrored, but I haven't investigated that far yet...
u_short myMap[x][y]={ {1,2,-1,...}, {-1,6,12...}, etc... };
because that way it is easier to visualise what your background will look like.
This is an array of unsigned longs, which provide a working area for the background handler. According to the manual, the size is calculated like this:
u_long BgWorkspace[(((screen width/16+1)*(screen height/16+1+1)*6+4)*2+2)]; I can see why you'd have the screen width and height divided by 16, but I don't know where the rest of the numbers come from. Ask Sony!