Sprite Sheet to Genesis Sprite List

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Sprite Sheet to Genesis Sprite List

Post by kubilus1 » Thu Nov 22, 2012 3:48 pm

I've written a shell script to take a single image or a horizontally arranged sprite sheet and convert it into a format more easily usable by the Genesis and sgdk. (Requires Imagemagick)

spriteit.sh -->

Code: Select all

#!/bin/sh

IMAGE=${1:?"Missing parameter IMAGE"}
WIDTH=${2:?"Missing parameter WIDTH"}
HEIGHT=${3:?"Missing parameter HEIGHT"}
NUMSPRITE=${4:?"Missing parameter NUMSPRITES"}

TEMPDIR=$(mktemp -d)

IMAGENAME=${IMAGE%.*}
convert ${IMAGE} -crop 8x8 BMP3:${TEMPDIR}/${IMAGENAME}_%d.bmp

CONCATLIST=""
CURINDEX=0
IMAGELEN=$(echo "${WIDTH} * ${NUMSPRITE} " | bc)
for i in $(seq ${IMAGELEN}); do
    CURINDEX=$(echo "${i} - 1" | bc)
    for j in $(seq ${HEIGHT}); do
        CONCATLIST="${CONCATLIST} ${TEMPDIR}/${IMAGENAME}_${CURINDEX}.bmp"
        CURINDEX=$(echo "${CURINDEX} + ${WIDTH}*${NUMSPRITE}" | bc)
    done
done

montage -mode concatenate -tile ${IMAGELEN}x${HEIGHT} ${CONCATLIST} BMP3:${IMAGENAME}_sprite.bmp
convert ${IMAGENAME}_sprite.bmp -colors 16 BMP3:${IMAGENAME}_sprite.bmp
rm -rf ${TEMPDIR}
Usage:

$ ./spriteit.sh animage.bmp 4 4 3


This will spit out 'animage_sprite.bmp'

In this case animage.bmp has three 32x32 pixel frames side by side. The input image type doesn't really matter, either, can be jpg, png, etc, it will spit out a bmp regardless.

------

In sgdk:

You can load the bmp just like any other in sgdk:

Code: Select all

    #include "animage_sprite.h"

    ....

    VDP_setPalette(PAL0, (u16 *) &animage_sprite[2]);
    VDP_loadBMPTileData((u32*) &animage_sprite[19], 1121, 12, 4, 12);

and animate the image by cycling over the starting tile positions:

Code: Select all

struct spritedef {
    s16 posx;
    s16 posy;
    u16 tile_attr;
    u8 size;
    u8 link;
    u32 startaddr;
    u8 steps;
};

    ...  

    int step=0;
    int sprite_step=3;
    struct spritedef runsprite;
    
    runsprite.posx = 0;
    runsprite.posy = 180;
    runsprite.size = SPRITE_SIZE(4,4);
    runsprite.steps = 3;    
    runsprite.startaddr = 1121;
    runsprite.tile_attr = TILE_ATTR_FULL(PAL0, 1, 0, 0, runsprite.startaddr+(16*(step%runsprite.steps)));
    runsprite.link = 0;

    for(i=0;i<350;i+=5)
    {
        runsprite.posx = i;
        runsprite.tile_attr = TILE_ATTR_FULL(PAL0, 1, 0, 0, runsprite.startaddr+(16*(step%runsprite.steps)));

        VDP_setSpriteP(0, &runsprite);
        VDP_updateSprites();
                VDP_waitVSync();
                VDP_waitVSync();
        step++;
    }

EDIT: Imagemagick 6.7.x and up requires that I specify the BMP type as BMP type 3, otherwise we an image without an indexed colormap.
Last edited by kubilus1 on Tue Dec 11, 2012 4:12 pm, edited 3 times in total.

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

Post by djcouchycouch » Thu Nov 22, 2012 4:30 pm

This will spit out 'animage_sprite.bmp'
did you mean 'animage_sprite.h' ?

kubilus1
Very interested
Posts: 237
Joined: Thu Aug 16, 2012 2:25 am
Contact:

Post by kubilus1 » Thu Nov 22, 2012 6:23 pm

did you mean 'animage_sprite.h' ?
No, it would spit out 'animage_sprite.bmp', it would be up to you to 'bintos' it into a .h and .s file. I suppose I left that step out.

Post Reply