Pour la version francaise, cliquez sur le drapeau :

Day 8 : Display Maps

We saw at day 4 that we could not display images of resolution higher than 512×512.
You said yourselves: “Saperlipopette! but how I will do my scrolling? 512 it is too little!” and you prepared to send to Brunni a head of horse to the foot of its bed…
Stop! not need to reach this point, before it is not its fault, but that of the designers of the PSP, and -put this axe on the ground- there is a solution to our problem : the maps ! :-)
(and then… saperlipopette… what is this expression ? :-D)

1) The preparations

We need for this tuto a big image (resolution higher than 512×512). Try do not take too large nor too provided in details, this is likely to wedge later, I will explain you later.
Edit this image with your favorite photo software in order to add at up of that image a band of 16 pixels top and fill of a color which does not exist in the image. (look at the image provided in the zip for better understanding, it acts of the pink band in top of the image : I pass from an image of 1024×1024 to an image of 1024×1040).
The reason is simple: OSLib considers that the first tile of the tileset gives the transparency for all the remainder of the map. You did not understand anything? don’t worry, try to don’t do it, you will see ;-)

Then download the last version of GBA Graphics, the Brunni’s map editor.

Finally, follow with attention each step of this:

If all its alright, check the resolution of your tileset.png, it does not have to exceed 512×512 (still!). Yes, always this limit imposed by the PSP :-( (if its happened to you, try to reduce the size of the image before passing it under GBA Graphics)
Then copy the file .h in the folder of your project (with the main.c)
Open it with notepad for example and note the name and the numbers being after const unsigned shorts

Here we notes Zora_map and 65 and 64.

2) The code

//The main library OSLib
#include <oslib/oslib.h>
 
//include the "data" of the map
#include "Zora.h"
 
//the callbacks
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
 
//definition of the pointers towards our image
OSL_IMAGE *Zora_tileset;
 
//definition of the pointers towards our map
OSL_MAP *zora;
 
//variables
int i;
 
int main()
{
	//Initialization of the library
	oslInit(0);
 
	//Initialization of the graphic mode 
	oslInitGfx(OSL_PF_8888, 1);
 
	//loading of our images (yes, the famous one :-P)
	Zora_tileset = oslLoadImageFile("tileset.png", OSL_IN_RAM, OSL_PF_5551);
	
	//check
	if (!Zora_tileset)
		oslDebug("Check if all the files are copied in the game folder.");
 
	//configuration of the map
	zora = oslCreateMap(
		Zora_tileset,						//Tileset
		Zora_map,						//Map
		16,16,							//Size of tiles
		64,65,							//Size of Map
		OSL_MF_U16);						//Format of Map
 
 
	//main loop
	while (!osl_quit)
	{
		//allow to draw
		oslStartDrawing();
 
		//clear the screen
		oslCls();
 
		//read the keys
		oslReadKeys();
 
		//Joystick for move our map
		for (i=32;i<=120;i+=48)
		{
			//following the x-axis
			if (osl_keys->analogX > i)
			{
				zora->scrollX += 2;				
			}
			if (osl_keys->analogX < -i)
			{
				zora->scrollX -= 2;				
			}	
 
			//then the y-axis
			if (osl_keys->analogY > i)
			{
				zora->scrollY += 2;				
			}
			if (osl_keys->analogY < -i)
			{
				zora->scrollY -= 2;				
			}
		}
		
		//draw the map
		oslDrawMapSimple(zora);
		
		//end of the draw
		oslEndDrawing();
 
		//Synchronize the screen
		oslSyncFrame();		
	}
	
	//leave the program
	oslEndGfx();
	oslQuit();
	return 0;
}

3) Explanations

Zora_tileset = oslLoadImageFile(”tileset.png”, OSL_IN_RAM, OSL_PF_5551);
Nothing new here, we load an image, and this image is the tileset of our map.

zora = oslCreateMap(
Zora_tileset,
Zora_map,
16,16,
64,65,
OSL_MF_U16);

It is here that you will configure the map to be displayed. So the first argument is the name of the image which contains the tileset.
The second is the name that I asked you to note before.
The third is the size of the tiles (selected in GBA Graphics before).
Finally the fourth is the size of the map, these are the numbers that you noted a few moments ago.
Yes they are reversed, but it is normal, the notation of the tables out of C is table[y][y]. I know, it is odd…
What? 5th? do not seek to understand and leave just as it is…

oslCls();
Clear the screen. Simple, no ?

zora- >scrollX += 2;
zora- >scrollY += 2;

I think that it is rather obvious, we ravels the map in x and y by modifying these variables there.

oslDrawMapSimple(zora);
There too it is rather obvious, this display the famous map.

4) Screen et eboot

Voila, you must obtain a trick like that :

Download the eboot compiled for 1.5


Personal Tools