Page 1 of 1

Issue with sprite drawing.

Posted: Fri Jul 28, 2017 7:40 am
by orlanrod
The sprite looks silhouette, but has the correct palette. On the right of the red silhouette, i pasted how the sprites actually look. I'm not sure what i am doing wrong.
testimg.png
testimg.png (13.92 KiB) Viewed 6562 times
My resource file has this

Code: Select all

SPRITE maleplayer_sprite "sprite/mainpltown.png" 2 2 -1 10
My Header has this

Code: Select all

#ifndef _RES_SPRITE_H_
#define _RES_SPRITE_H_

extern const SpriteDefinition maleplayer_sprite;

#endif // _RES_SPRITE_H_
My main looks like this

Code: Select all

#include <genesis.h>
#include "sprite.h"

#define ANIM_STAND      0
#define ANIM_WALKDOWN   1

#define MIN_POSX        FIX32(10)
#define MAX_POSX        FIX32(400)
#define MAX_POSY        FIX32(156)

// sprites structure (pointer of Sprite)
Sprite* sprites[3];


fix32 posx;
fix32 posy;
fix32 movx;
fix32 movy = 1;
s16 xorder;
s16 yorder;

int main()
{
	VDP_drawText("Orlan Rod checking in!", 10, 13);

    u16 palette[64];

    // disable interrupt when accessing VDP
    SYS_disableInts();
    // initialization
    VDP_setScreenWidth320();

    // init sprites engine
    SPR_init(0, 256, 256);

    // VDP process done, we can re enable interrupts
    SYS_enableInts();


    posx = FIX32(48);
    posy = MAX_POSY;
    movx = FIX32(0);
    movy = FIX32(0);
    xorder = 0;
    yorder = 0;



    // init player sprite
    sprites[0] = SPR_addSprite(&maleplayer_sprite, fix32ToInt(posx), fix32ToInt(posy), TILE_ATTR(PAL1, TRUE, FALSE, FALSE));

    SPR_update();

    // prepare palettes
    memcpy(&palette[0], maleplayer_sprite.palette->data, 16 * 2);
    //memcpy(&palette[16], bga_image.palette->data, 16 * 2);



	while(1)
	{
		//read input
		//move sprite
		//update score
		//draw current screen (logo, start screen, settings, game, gameover, credits...)

		//wait for screen refresh

        // update sprites
        SPR_update();
		VDP_waitVSync();
	}


	return (0);
}

Re: Issue with sprite drawing.

Posted: Fri Jul 28, 2017 10:03 am
by Moon-Watcher
Try

Code: Select all

memcpy(&palette[16], maleplayer_sprite.palette->data, 16);

Re: Issue with sprite drawing.

Posted: Fri Jul 28, 2017 11:04 am
by Sik
memcpy works on bytes, not words.

Also it was already stated that the palette is correct. Given the silhouette is obviously from the intended sprite, if that's indeed the case it means the problem is not in the code at all, but how the sprite is getting converted into tiles. So look into how the sprites are being converted.

Re: Issue with sprite drawing.

Posted: Fri Jul 28, 2017 11:28 am
by Moon-Watcher
Ops! just notice... where do you use "palette" var?

Re: Issue with sprite drawing.

Posted: Sat Jul 29, 2017 7:16 am
by dub
Maybe you're not writing the good palette :

Code: Select all

 // init player sprite
    sprites[0] = SPR_addSprite(&maleplayer_sprite, fix32ToInt(posx), fix32ToInt(posy), TILE_ATTR(PAL1, TRUE, FALSE, FALSE));

    SPR_update();

    // prepare palettes
    memcpy(&palette[0], maleplayer_sprite.palette->data, 16 * 2);	//-->PAL0
    
sprites[0] = SPR_addSprite(&maleplayer_sprite, fix32ToInt(posx), fix32ToInt(posy), TILE_ATTR(PAL0, TRUE, FALSE, FALSE));

Re: Issue with sprite drawing.

Posted: Mon Jul 31, 2017 12:41 am
by orlanrod
dub wrote:
Sat Jul 29, 2017 7:16 am
Maybe you're not writing the good palette :

Code: Select all

 // init player sprite
    sprites[0] = SPR_addSprite(&maleplayer_sprite, fix32ToInt(posx), fix32ToInt(posy), TILE_ATTR(PAL1, TRUE, FALSE, FALSE));

    SPR_update();

    // prepare palettes
    memcpy(&palette[0], maleplayer_sprite.palette->data, 16 * 2);	//-->PAL0
    
sprites[0] = SPR_addSprite(&maleplayer_sprite, fix32ToInt(posx), fix32ToInt(posy), TILE_ATTR(PAL0, TRUE, FALSE, FALSE));
Nope, it just displays the same silhouette, but in white. This is the same code found in the example sprite source of the sgdk. Hmm

Re: Issue with sprite drawing.

Posted: Mon Jul 31, 2017 12:49 am
by orlanrod
Solved. Removed code that needed to be there

Code: Select all

    // set all palette to black
    VDP_setPaletteColors(0, (u16*) palette_black, 64);
    
    // fade in
    VDP_fadeIn(0, (4 * 16) - 1, palette, 20, FALSE);