SPR_addSpriteEx Flags

SGDK only sub forum

Moderator: Stef

Post Reply
Yukiko
Interested
Posts: 13
Joined: Sat Nov 18, 2017 9:33 am

SPR_addSpriteEx Flags

Post by Yukiko » Sun Dec 24, 2017 4:13 am

I'm trying to manually allocate the sprite index.

Code: Select all

Sprite* SPR_addSpriteEx(const SpriteDefinition * spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flags )

Code: Select all

case AYA_KALANG :
	sprites[i] = SPR_addSpriteEx(&character_aya, Party[i][1]-100, Party[i][2], TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	break;
case KAYLIN_MATZNER :
	sprites[i+12] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16+24, Party[i][2]+43, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 21+1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	sprites[i+8] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16, Party[i][2]+43, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 21+2, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	sprites[i+4] = SPR_addSpriteEx(&character_kaylin_mouth, Party[i][1]+32, Party[i][2]+64, TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 21+3, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	sprites[i] = SPR_addSpriteEx(&character_kaylin, Party[i][1], Party[i][2], TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 21, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	break;
case KIAH_STONE :
	sprites[i+12] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16+24, Party[i][2]+41, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 41+1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	sprites[i+8] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16, Party[i][2]+41, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 41+2, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	sprites[i+4] = SPR_addSpriteEx(&character_kiah_mouth, Party[i][1]+32, Party[i][2]+63, TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 41+3, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	sprites[i] = SPR_addSpriteEx(&character_kiah, Party[i][1], Party[i][2], TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 41, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
	break;
This code works, and fills the sprite index 1-69.

Code: Select all

case AYA_KALANG :
	sprites[i] = SPR_addSpriteEx(&character_aya, Party[i][1]-100, Party[i][2], TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	break;
case KAYLIN_MATZNER :
	sprites[i+12] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16+24, Party[i][2]+43, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 21+1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	sprites[i+8] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16, Party[i][2]+43, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 21+2, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	sprites[i+4] = SPR_addSpriteEx(&character_kaylin_mouth, Party[i][1]+32, Party[i][2]+64, TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 21+3, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	sprites[i] = SPR_addSpriteEx(&character_kaylin, Party[i][1], Party[i][2], TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 21, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	break;
case KIAH_STONE :
	sprites[i+12] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16+24, Party[i][2]+41, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 41+1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	sprites[i+8] = SPR_addSpriteEx(&character_kaylin_eyes, Party[i][1]+16, Party[i][2]+41, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 41+2, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	sprites[i+4] = SPR_addSpriteEx(&character_kiah_mouth, Party[i][1]+32, Party[i][2]+63, TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 41+3, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	sprites[i] = SPR_addSpriteEx(&character_kiah, Party[i][1], Party[i][2], TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 41, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
	break;
I changed the code to remove the SPR_FLAG_AUTO_SPRITE_ALLOC so that I could try and manually allocate the sprites. However, the only sprite index 0 is being filled. I'm guessing I need to call another function for manual allocation.

User avatar
Stef
Very interested
Posts: 2760
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPR_addSpriteEx Flags

Post by Stef » Tue Dec 26, 2017 10:07 am

When you pass to manual allocation you need to use the following method :

Code: Select all

SPR_setSpriteTableIndex(Sprite)
To give the hardware sprite index to use for this sprite. You need to ensure you have enough available hard sprite at this position to fit the number of hard sprite requirement for this sprite, link field between hard sprite should be correctly set as well.

Yukiko
Interested
Posts: 13
Joined: Sat Nov 18, 2017 9:33 am

Re: SPR_addSpriteEx Flags

Post by Yukiko » Wed Dec 27, 2017 3:01 am

Thanks for the help. I tried searching for that function in use, but there doesn't seem to be a public example.

Code: Select all

sprites[i] = SPR_addSpriteEx(&character_aya, 20, 20, TILE_ATTR(PAL2, TRUE, FALSE, FALSE), 1, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD);
How should the first attribute for SPR_setSpriteTableIndex be written in the above code? Does it go before or after SPR_addSpriteEx?
Last edited by Yukiko on Wed Dec 27, 2017 11:35 pm, edited 1 time in total.

User avatar
Stef
Very interested
Posts: 2760
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPR_addSpriteEx Flags

Post by Stef » Wed Dec 27, 2017 11:00 am

Oh you're right, you should be ab le to do it from addSpriteEx(..), i forgot you had the spriteIndex parameter in it, my bad...
Well in fact it should work with your first code :

Code: Select all

sprites[i+4] = SPR_addSpriteEx(&character_kaylin_mouth, Party[i][1]+32, Party[i][2]+64, TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 21+3, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
sprites[i] = SPR_addSpriteEx(&character_kaylin, Party[i][1], Party[i][2], TILE_ATTR(PAL1, TRUE, FALSE, FALSE), 21, SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_SPRITE_ALLOC);
I need to investigate to understand why you sprite index is not correctly set to 24 and 21 respectively in this case as it should.
Normally you should use any SPR_setXXX(sprite) method always *after* the sprite has been allocated / added of course, but here indeed you don't even need it as addSpriteEx(..) should be enough to set manually the sprite index.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest