Stef wrote:How many tiles you reserve for the sprite engine (SPR_init(..) call) ?
Also i don't understand what you are doing with the palette preparation after actually setting them ?
It's set to 256, but now i set it to 0 and still nothing. The background image i am trying to draw is 1024x1024
Here is the full main code
#include <genesis.h>
#include <vdp.h>
#include <vdp_pal.h>
#include <gfx.h>
#define ANIM_STANDSIDES 0
#define ANIM_WALKSIDES 1
#define ANIM_SLEEPSIDES 3
#define ANIM_STANDDOWN 4
#define ANIM_WALKDOWN 5
#define ANIM_SLEEPDOWN 6
#define ANIM_STANDUP 7
#define ANIM_WALKUP 8
#define MIN_POSX FIX32(10)
#define MAX_POSX FIX32(400)
#define MIN_POSY FIX32(10)
#define MAX_POSY FIX32(400)
// forward
static void handleInput();
static void joyEvent(u16 joy, u16 changed, u16 state);
static void updateAnim();
static void updateCamera(fix32 x, fix32 y);
// sprites structure
Sprite sprites[2];
fix32 camx;
fix32 camy;
fix32 posx;
fix32 posy;
fix32 movx;
fix32 movy;
s16 xorder;
s16 yorder;
u16 current_anim;
u16 php = 99; //player hp
u16 psp = 0; //player special power.
char str[8];
int main()
{
u16 palette[64];
u16 ind;
// disable interrupt when accessing VDP
SYS_disableInts();
// initialization
VDP_setScreenWidth320();
// init sprites engine
SPR_init(0);
VDP_setPaletteColors(0, palette_black, 64);
// load background
ind = TILE_USERINDEX;
VDP_drawImageEx(BPLAN, &bgb_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
ind += bgb_image.tileset->numTile;
// VDP process done, we can re enable interrupts
SYS_enableInts();
camx = -1;
camy = -1;
posx = 150;
posy = 100;
xorder = 0;
yorder = 0;
current_anim = 0;
// init jason sprite
SPR_initSprite(&sprites[0], &jason_sprite, posx, posy, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
SPR_update(sprites, 1);
// prepare palettes
memcpy(&palette[0], bgb_image.palette->data, 16 * 2);
memcpy(&palette[32], jason_sprite.palette->data, 16 * 2);
// fade in
VDP_fadeIn(0, (3 * 16) - 1, palette, 20, FALSE);
JOY_setEventHandler(joyEvent);
while(TRUE)
{
handleInput();
updateAnim();
updateCamera(camx, camy);
//VDP_drawText("Hello World!", 1, 1);
// update sprites (only one to update here)
SPR_update(sprites, 1);
VDP_waitVSync();
}
return 0;
}
static void updateCamera(fix32 x, fix32 y)
{
fix32 cx = x;
fix32 cy = y;
VDP_setHorizontalScroll(PLAN_B, cx);
VDP_setVerticalScroll(PLAN_B, cy);
u16 value = JOY_readJoypad(JOY_1);
if ((value & BUTTON_RIGHT) && camx > -352) camx -= 1;
if ((value & BUTTON_LEFT) && camx < -1) camx += 1;
if ((value & BUTTON_UP) && camy > -1) camy -= 1;
if ((value & BUTTON_DOWN) && camy < 256) camy += 1;
}
static void updateAnim()
{
if (current_anim == ANIM_WALKSIDES) SPR_setAnim(&sprites[0], ANIM_WALKSIDES);
if (current_anim == ANIM_WALKUP) SPR_setAnim(&sprites[0], ANIM_WALKUP);
if (current_anim == ANIM_WALKDOWN) SPR_setAnim(&sprites[0], ANIM_WALKDOWN);
if (yorder == 0 && xorder == -1) current_anim = ANIM_WALKSIDES;
if (yorder == 0 && xorder == +1) current_anim = ANIM_WALKSIDES;
if (yorder == -1 && xorder == 0) current_anim = ANIM_WALKUP;
if (yorder == +1 && xorder == 0) current_anim = ANIM_WALKDOWN;
if (yorder == 0 && xorder == 0)
{
if (current_anim == ANIM_WALKSIDES) SPR_setAnim(&sprites[0], ANIM_STANDSIDES);
if (current_anim == ANIM_WALKUP) SPR_setAnim(&sprites[0], ANIM_STANDUP);
if (current_anim == ANIM_WALKDOWN) SPR_setAnim(&sprites[0], ANIM_STANDDOWN);
}
}
static void handleInput()
{
u16 value = JOY_readJoypad(JOY_1);
if ((value & BUTTON_RIGHT) && posx < 300 && camx <= -352)
{
posx += 1;
SPR_setPosition(&sprites[0], posx, posy);
}
if ((value & BUTTON_RIGHT) && posx < 150)
{
posx += 1;
SPR_setPosition(&sprites[0], posx, posy);
}
if ((value & BUTTON_RIGHT))
{
SPR_setAttribut(&sprites[0], TILE_ATTR(PAL2,TRUE,FALSE,FALSE));
}
if ((value & BUTTON_LEFT) && posx > 5 && camx >= -1)
{
posx -= 1;
SPR_setPosition(&sprites[0], posx, posy);
}
if ((value & BUTTON_LEFT) && posx > 150)
{
posx -= 1;
SPR_setPosition(&sprites[0], posx, posy);
}
if ((value & BUTTON_LEFT))
{
SPR_setAttribut(&sprites[0], TILE_ATTR(PAL2,TRUE,FALSE,TRUE));
}
if (value & BUTTON_LEFT) xorder = -1;
else if (value & BUTTON_RIGHT) xorder = +1;
else xorder = 0;
if ((value & BUTTON_UP) && posy > 5 && camy >= -1)
{
posy -= 1;
SPR_setPosition(&sprites[0], posx, posy);
}
if ((value & BUTTON_DOWN) && posy < 240 && camy >= 256)
{
posy += 1;
SPR_setPosition(&sprites[0], posx, posy);
}
if (value & BUTTON_UP) yorder = -1;
else if (value & BUTTON_DOWN) yorder = +1;
else yorder = 0;
}
static void joyEvent(u16 joy, u16 changed, u16 state)
{
// START button state changed
if (changed & BUTTON_START)
{
}
}