Issue with sprite drawing.

SGDK only sub forum

Moderator: Stef

Post Reply
orlanrod
Very interested
Posts: 95
Joined: Fri Sep 25, 2015 7:46 pm

Issue with sprite drawing.

Post by orlanrod » Fri Jul 28, 2017 7:40 am

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 388 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);
}
Attachments
mainpltown.png
mainpltown.png (384 Bytes) Viewed 388 times

Moon-Watcher
Very interested
Posts: 115
Joined: Sun Jan 02, 2011 9:14 pm

Re: Issue with sprite drawing.

Post by Moon-Watcher » Fri Jul 28, 2017 10:03 am

Try

Code: Select all

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

User avatar
Sik
Very interested
Posts: 591
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Issue with sprite drawing.

Post by Sik » Fri Jul 28, 2017 11:04 am

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.
Sik is pronounced as "seek", not as "sick".

Moon-Watcher
Very interested
Posts: 115
Joined: Sun Jan 02, 2011 9:14 pm

Re: Issue with sprite drawing.

Post by Moon-Watcher » Fri Jul 28, 2017 11:28 am

Ops! just notice... where do you use "palette" var?

dub
Very interested
Posts: 98
Joined: Thu Mar 19, 2015 1:26 pm

Re: Issue with sprite drawing.

Post by dub » 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));

orlanrod
Very interested
Posts: 95
Joined: Fri Sep 25, 2015 7:46 pm

Re: Issue with sprite drawing.

Post by orlanrod » Mon Jul 31, 2017 12:41 am

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

orlanrod
Very interested
Posts: 95
Joined: Fri Sep 25, 2015 7:46 pm

Re: Issue with sprite drawing.

Post by orlanrod » Mon Jul 31, 2017 12:49 am

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);

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest