Page 1 of 1

Drawing graphics and sprites

Posted: Thu Mar 20, 2014 10:49 pm
by Kuroto
Hi,

So i'm trying to write a little game right now, to get into some genny coding.
Now, as far as i understand, there's 2 "planes" which can be used to draw background graphics, along with a sprite layer.

I managed to draw a simple BMP background on plane B, but now i'd like to draw a little "logo" on plane A, in front of the background.

This is the code i currently have, which seems to work.

Code: Select all

#include <genesis.h>

struct genresTiles
{
		u16 *pal; 		//pointer to pal data
		u32 *tiles;		//pointer to tiles data
		u16 width;		//width in tiles
		u16 height;		//height in tiles
		u16 compressedSize; //0 in this demo, more coming soon
};



extern struct genresTiles citybg;
extern struct genresTiles logo;

#define TILE1	1



int main( )
{
	VDP_setPalette(PAL1, citybg.pal);

	// load tiles in VRAM
	//  arg0 = tiles data
	//  arg1 = index for first destination tile
	//  arg2 = number of tiles to load
	//  arg3 = use DMA (1) or not (0)
	VDP_loadTileData(citybg.tiles, TILE1, citybg.width*citybg.height, 0);

    // City background fill
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 0, -4, citybg.width, citybg.height);
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 16, -4, citybg.width, citybg.height);
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 32, -4, citybg.width, citybg.height);



	VDP_drawText("SCORE:", 0,0);
	VDP_drawText("00", 38, 0);


	while(1)
	{
		VDP_waitVSync();
	}
	return 0;
}
I tried using the same method to draw to plane A instead of plane B, but it doesn't seem to work.

Any pointers?

Thanks :)

Posted: Sat Mar 22, 2014 12:38 pm
by MintyTheCat
Hi,

if you are using SGDK:

VDP_fillTileMapRectInc(<Address of your Planes in VRAM>, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 0, -4, citybg.width, citybg.height);

Would become:

VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 0, -4, citybg.width, citybg.height);

Change the BPLAN to APLAN.

Posted: Sat Mar 22, 2014 8:23 pm
by Kuroto
Hi MintyTheCat,

Thanks for the info.

I tried as you suggested, but that didn't seem to work.

With the current code (see below), it seems to draw everything on Plane B.
The logo is drawn at the very bottom if i view it in Gens KMod.
Not sure why...

Code: Select all

#include <genesis.h>



struct genresTiles
{
		u16 *pal; 		//pointer to pal data
		u32 *tiles;		//pointer to tiles data
		u16 width;		//width in tiles
		u16 height;		//height in tiles
		u16 compressedSize; //0 in this demo, more coming soon
};



extern struct genresTiles citybg;
extern struct genresTiles logo;

#define TILE1	1
#define TILE2	1



int main( )
{
	VDP_setPalette(PAL1, citybg.pal);

	// load tiles in VRAM
	//  arg0 = tiles data
	//  arg1 = index for first destination tile
	//  arg2 = number of tiles to load
	//  arg3 = use DMA (1) or not (0)
	VDP_loadTileData(citybg.tiles, TILE1, citybg.width*citybg.height, 0);
	VDP_loadTileData(logo.tiles, TILE2, logo.width*logo.height, 0);

    // City background fill
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 0, -4, citybg.width, citybg.height);
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 16, -4, citybg.width, citybg.height);
	VDP_fillTileMapRectInc(BPLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE1), 32, -4, citybg.width, citybg.height);
	VDP_fillTileMapRectInc(APLAN, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE2), 0, -4, logo.width, logo.height);


	VDP_drawText("SCORE:", 0,0);
	VDP_drawText("00", 38, 0);


	while(1)
	{
		VDP_waitVSync();
	}
	return 0;
}

Posted: Sat Mar 22, 2014 8:58 pm
by MintyTheCat
Hi,

a couple of things:

1. there's actually a seperate SGDK section that you could post in as there are People who are using SGDK there so you can find some support.

2. without thinking too much about it I would say that you need to check your Priority settings. In the MD all Tiles are positioned according to each Tile's Tile-Map Entry found in the Tile-Map so if you are not sure you can interrogate that to make sure that you end up with the correct settings for the Tiles and indeed the Planes. There are rules but if A:Pri=1 and B:Pri=1 then A 'wins'. So check that B:Priority is set and see that A's is not.

I would check the resulting Tile-Map Entries first or any flag set in SGDK's Functions.

Posted: Sat Mar 22, 2014 9:23 pm
by Kuroto
OK, i'll create a new thread in the SGDK subforum then :)
Thanks!