I fail to see or to animate a sprite with genres method.
I have this code which is almost the same as in the tutorial :
Code: Select all
#include <genesis.h>
typedef struct
{
s16 posx;
s16 posy;
u16 tile_attr;
u8 size;
u8 link;
u32 startaddr;
u8 steps;
} _spritedef;
struct genresSprites
{
u16 *pal; //pointer to pal data
u32 **sprites; //pointer to sprites data
u16 count; //nb sprites
u16 width; //width of each sprite in pixels (not tiles!)
u16 height; //height of each sprite in pixels (not tiles!)
u16 size; //since we use width/height in pixel, useful info on sprite size
//TODO : size is not SGDK compliant, you need to use size>>8
//will be fixed in coming release
};
int main()
{
struct genresSprites sonicTEST;
_spritedef SonicSprite;
u16 nbTiles = (sonicTEST.height>>3) * (sonicTEST.width>>3);
VDP_loadTileData( sonicTEST.sprites[1], 1, nbTiles, 0);
// load in PAL2
VDP_setPalette(PAL2, sonicTEST.pal);
VDP_resetSprites();
VDP_setSprite(0, 0, 0, sonicTEST.size>>8, TILE_ATTR_FULL(PAL2,1,0,0,1), 0);
VDP_updateSprites();
u8 frame = 1;
// define the sprite (using a _spritedef to easily make Sonic move later)
SonicSprite.posx = 40;
SonicSprite.posy = 40;
SonicSprite.size = sonicTEST.size>>8;
SonicSprite.tile_attr = TILE_ATTR_FULL(PAL2,1,0,0,1);
SonicSprite.link = 0;
VDP_setSpriteP(0, &SonicSprite);
//GAME LOOP
while(1)
{
// we still use nbTiles since ALL sprite are of the size in a sprite sheet
VDP_loadTileData( sonicTEST.sprites[frame + 1], 1, nbTiles, 0);
frame++; // next frame
frame%=3; // we only need 3 frames, so roll back
//make it move!
SonicSprite.posx+=10;
VDP_setSpriteP(0, &SonicSprite);
//flush
VDP_updateSprites();
// .... code
VDP_waitVSync();
}
return (0);
}
I don't understand what's the problem. I see on my screen two red squares moving
instead of sonic sprite.
I have in my folder src the file resource.c of tutoriel :
Code: Select all
; to put the data in a "res" folder, else it will compiled by GenRes AND GDK's bitmap compiler
SPRITE sonic "data/sonic.bmp" 24 32 0 7
; it's VERY important to finish by a new line ! else the last resource won't be compiled
In short, if someone can help me because it's been a few days that I'm stuck.
Thank you in advance.