SGDK is a fantastic library for developing games for the Sega Genesis/Mega Drive. There are plenty of resources for learning how to use SGDK. Such as the the wiki, SpritesMind.net and the tutorials by ohsat games and danibus games. So I don’t plan on writing a bunch of tutorials for it. My blog will cover things that I had trouble with or find interesting.
Sprite Image Creation
The Sega Genesis is a fun system to program, but has some strict limitations. One of which is the limited color palette. Sega Genesis sprites can only be 16 colors.
GIMP
Create an image using “File|New…”. Set the image width and height to a size supported by SGDK.
Convert the image to an Indexed Image using “Image|Mode|Indexed…”. Choose a palette with 16 colors or fewer.
- You can use the “Colormap” Dockable Dialog to edit colors if needed.
Draw your sprite. Take care to use only 15 color or fewer. The first color is the background color and will be transparent when rendered by SGDK.
Once you’re doing editing your image, export it as a PNG with “File|Export As…”
Pro Motion NG
- Create a new project using “File|New Project|Create …”. Set the image width and height to a size supported by SGDK.
- In the “Create a new Project” dialog box set the size of your image, the Type to “Sega Megadrive/Genesis (Generic)” and the Color Palette to “rainbow333.pal”
Draw your sprite. Take care to use only 15 colors or fewer. The first color is the background color and will be transparent when rendered by SGDK.
Reduce the colors in your image to 16. Use “Colors|Reduce Colors…”
- Once you’re doing editing your image, save it as a PNG with “File|Save Image As…”
Basic Sprite Example
Sprite Specific Code
SGDK makes it easy to load and display sprites from images. At a minimum you want to 1. Define a sprite resource in res/resources.res
SPRITE ship "sprites/ship.png" 2 2 NONE
- Load the color palette of the sprite resource
VDP_setPalette( PAL1, ship.palette->data );
- Initialize the sprite engine
SPR_init()
- Create a Sprite with SPR_addSprite()
Sprite *shipSprite = NULL;// Sprite name from resources.res
shipSprite = SPR_addSprite( &ship, 152, // starting X position
102, // starting Y position
TILE_ATTR( // Palette index
PAL1, 0, // Palette index
// Vertical Flip
FALSE, // Horizontal Flip
FALSE ));
- Update the sprite engine in the main game loop
SPR_update();
The full source code can be found at github