Help converting sprites to MD

SGDK only sub forum

Moderator: Stef

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Help converting sprites to MD

Post by Manveru » Wed Sep 05, 2012 3:54 pm

Hello everyone. I am Spanish and my English is not very good so apologize me.

I began a few days ago a new adventure with SGDK, and after i had been using libraries like Fenix/Bennu or Allegro some time ago, i discovered i am a nooby coding for Genesis. I had done and made some trials will all the wiki tutorials and i think i understad them, but after i had tried a lot of ways i can´t convert my sprites to MD format.

I am working from GenRes's SPRITE support, working with a sprite sheet, but each attemp i try converting my sheet to a Genesis compatible format doesn't work. I have read about 16 colors, 256 or 512, 8 pixel aligned... but i don´t understand for example how i can make transparencies (in Sonic tutorial the green backgroud is transparent on emulator but i doesn't work with my sheet) or the .size attribute. I think i need a program that convert my file to a compatible bmp, but all the programs i have read in wiki convert them to asm or bin and them i am completely lost with that.

Thanks for reading, i am waiting for your help.
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

ammianus
Very interested
Posts: 124
Joined: Sun Jan 29, 2012 2:10 pm
Location: North America
Contact:

Post by ammianus » Wed Sep 05, 2012 11:40 pm

Have you already taken a look at the Tools forum? I've used _mic's tool called "sixpack" with some modifications. Read about it in this thread

I don't work with sprite sheets, I just create separate image files for each sprite image, so that may not be useful.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu Sep 06, 2012 12:03 am

Hi there,

For transparencies, the pixels you want transparent need to be the first color in the 16 color palette. It'll work automatically. It doesn't matter what the actual color is, it just has to be the first one.

Hopefully this will make it more clear:

Code: Select all

palette colors:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

example sprite:

0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 1 1 2 1 1 0
0 1 2 2 2 1 0
0 1 1 2 1 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0
The pixels of the sprite that are using color 0 from the palette will be transparent.

Edit: I also use SGDK's support for genres and it works great.

My resource.rc looks something like this:

Code: Select all

SPRITE goplanesSprite "data/goplanes.bmp" 24 24 ; individual sprites are 24x24 and the .bmp contains about 30 frames.
SPRITE fireballSprite "data/fireball.bmp" 16 16
SPRITE fireballPickupSprite "data/fireball_pickup.bmp" 24 24                         
; always finish with a blank line or comment

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Post by Manveru » Thu Sep 06, 2012 2:30 am

Thanks ammianus. I have tried sixpack but it is a bit difficult for me. I tested it converting a bmp various times but it didn't work, surely i was doing something wrong. I have read about an easy and intuitive tool called ImaGenesis. It seems nice but when i convert my bmp to 4bpp and i load it in my code SGDK compiler says the sprite is not 4bpp...
So i am sorry but i need some "for dummies" help and tools.

PD: In other forums about other libraries people recomend to load just 1 parent bitmap and then catch every sprite from it better than loading one for every sprite, to get better performance, i don´t know if it is true...



Thanks djcouchycouch. Ok i understand it. So now i need a tool to convert properly a bmp to 16 colors (i don't know how to do with Gimp and in MsPaint i get a poor result). Then i guess i need another one to edit the sprite and the palette so the transparect color match.

I see in your Resource.rc that the size of your frames is 16x16 or 24x24. In the wiki example they are 24x32. I know the bitmap size should be 8 pixel aligned but when i try 32x40 compiler loads 32x32... Its .size attribute is

Code: Select all

sonic.size = SPRITE_SIZE(4,5);
i dont know where is the issue.
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Sep 06, 2012 6:35 am

Max size sprite is 32*32

So to draw a 40*32 sprite you would use 2 sprites. 32*32 and 8*32.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Thu Sep 06, 2012 9:59 am

the lib for multi-sprites (>32x32) isn't available yet, sorry... no times to polish it :(

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Post by Manveru » Thu Sep 06, 2012 2:56 pm

Thanks guys. I was beginning to think the maximun size is 32x32, thanks for confirm oofwill. No need to apologize KanedaFr, thanks for your work, do it when you can. I am learning working on a Sonic game and sonic sprites are about 29x39 so i will use 2 sprites as oofwill said.

By the way i tried to convert a bmp to 16 colors with Gimp but the SGDK compiler says something like "bmp header not compatible", and as i said MsPaint with 16 color returns a bad quality sprite... Do you recomend me another software, Photoshop for example?
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

lingh
Interested
Posts: 20
Joined: Thu Sep 06, 2012 4:57 am

Post by lingh » Thu Sep 06, 2012 3:11 pm

djcouchycouch wrote:For transparencies, the pixels you want transparent need to be the first color in the 16 color palette.
Not necesarry.

For Example -> SPRITE spritesDW "data/spritesDW.bmp" 32 32 0 2
Last number (2) - is number of transparent color for image. You can see palette in XnView and colors start counts from 0 to 15.
Manveru wrote: By the way i tried to convert a bmp to 16 colors with Gimp but the SGDK compiler says something like "bmp header not compatible", and as i said MsPaint with 16 color returns a bad quality sprite... Do you recomend me another software, Photoshop for example?
Yep, i encounter same problem.

Ok, how to change image to 4 bit in GIMP.
Image->Mode->Indexed... (if it alredy selected, you can choose first RGB mode and after him Indexed)
When choose generate optimum palette and choose 16 colors.
Press convert.

You also can change order of colors in Colours->Map->Rearrange Colourmap

To fix bmp, when you Export image, in Compability Options check field Do no write colour space information

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu Sep 06, 2012 3:44 pm

Not necesarry.

For Example -> SPRITE spritesDW "data/spritesDW.bmp" 32 32 0 2
Last number (2) - is number of transparent color for image. You can see palette in XnView and colors start counts from 0 to 15.
Seems to me like Genres might be doing something during the bitmap conversion to support that. The hardware doc I looked up (Genesis_technical_overview.doc) says that the first color of each palette is always transparent. Could be wrong, though.

For making sprites, I use Graphics Gale. It's more geared to towards sprite work.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Post by Manveru » Thu Sep 06, 2012 3:51 pm

Thanks lingh, now i can make transparences on sprites and Gimp seems to work...well maybe, this is my sprite sheet (160x32, 5 frames 32x32)

Image

and this is what i get on an emu (5 frames the same result):

Image
(seems like it draws a 16x32 sprite)

My resources.rc code is:

Code: Select all

SPRITE sonic "data/sonic.bmp" 32 32 0 0
I don't know where is the issue...
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

lingh
Interested
Posts: 20
Joined: Thu Sep 06, 2012 4:57 am

Post by lingh » Thu Sep 06, 2012 3:54 pm

djcouchycouch wrote:Seems to me like Genres might be doing something during the bitmap conversion to support that.For making sprites, I use Graphics Gale. It's more geared to towards sprite work.
Yes, its GenRes feature.
And thanks for prog name, check this out later.

lingh
Interested
Posts: 20
Joined: Thu Sep 06, 2012 4:57 am

Post by lingh » Thu Sep 06, 2012 3:56 pm

Manveru well sprite loaded and look half descent, palette looks ok to.

Post code for drawing.

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Post by Manveru » Thu Sep 06, 2012 4:08 pm

resources.rc

Code: Select all

SPRITE sp_parent_sonic "data/sonic.bmp" 32 32 0 0
main.c

Code: Select all

typedef struct
{
    SpriteDef sp_sonic;
	u16 nbTiles;
	u8 status;
	u8 frame;
	int speed, count;
	u8 flags;

} hedgehog;

struct genresSprites
{
		u16 *pal;
		u32 **sprites;
		u16 count;
		u16 width;
		u16 height;
		u16 size;
};
extern struct genresSprites sp_parent_sonic;

int main( )
{
    hedgehog sonic;
    sonic.nbTiles = sp_parent_sonic.count;

    sonic.sp_sonic.posx = 40;
    sonic.sp_sonic.posy = 140;
    sonic.sp_sonic.size = SPRITE_SIZE(4,4); //i test sp_parent_sonic.size>>8; too.
    sonic.sp_sonic.tile_attr = TILE_ATTR_FULL(PAL1,1,0,0,TILE1+sonic.nbTiles);
    sonic.sp_sonic.link  = 0;

    VDP_setPalette(PAL1, sp_parent_sonic.pal);
    VDP_loadTileData( sp_parent_sonic.sprites[0], TILE1+sonic.nbTiles, sonic.nbTiles, 0);

    while(1)
    {
        VDP_setSpriteP(0, &sonic.sp_sonic);
    	VDP_updateSprites();

    	VDP_waitVSync();
    }
    return 0;
}
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

lingh
Interested
Posts: 20
Joined: Thu Sep 06, 2012 4:57 am

Post by lingh » Thu Sep 06, 2012 4:16 pm

Manveru

Change

Code: Select all

sonic.nbTiles = sp_parent_sonic.count; 
to

Code: Select all

sonic.nbTiles = (sp_parent_sonic.width >> 3) * (sp_parent_sonic.height >> 3); 

Manveru
Very interested
Posts: 85
Joined: Wed Sep 05, 2012 3:30 pm

Post by Manveru » Thu Sep 06, 2012 4:32 pm

lingh wrote:Manveru

Change

Code: Select all

sonic.nbTiles = sp_parent_sonic.count; 
to

Code: Select all

sonic.nbTiles = (sp_parent_sonic.width >> 3) * (sp_parent_sonic.height >> 3); 
It works!!! thanks lingh, you are my hero :wink:

I thought .count was the number of frames in sprite, it worked well with the wiki code.
The man who moves a mountain begins by carrying away small stones. Confucius, 551-479 BC

Post Reply