Problem change sprite size in game

SGDK only sub forum

Moderator: Stef

Post Reply
dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Problem change sprite size in game

Post by dub » Fri Jun 10, 2016 2:19 pm

Hi,

In game, I change the tile of a sprite, resize the sprite and setposition.

With the old sgdk, all works in on frame.
With the new. The first frame show the new tile but old sprite size and the next frame evrything works.

As an example, made with photoshop to show you
Image

In Purple, 2 sprites (32*32). In yellow, loading new tiles, In green : new sprite size and position.

Code: Select all

//load new bitmap tiles
u16 wm = nTiles.w; 
	u16 hm = nTiles.h; 
	
	VDP_loadBMPTileData((u32*) nTiles.image,  nIndex, wm / 8, hm / 8, wm / 8 );	
				
//new position and new size
			players[0].posY = FIX32(112) + FIX32(16);
			players[1].posY = FIX32(112) + FIX32(32);
			players[0].posX = players[1].posX + FIX32(16);
			players[0].size_spriteH = 2;
			players[0].size_spriteV = 2;
			players[1].size_spriteH = 4;
			players[1].size_spriteV = 4;
			players[1].index = players[0].index + 4;
			
			players[0].numanim++;
//change sprite value			
			VDP_setSprite(players[0].numSprite, fix32ToInt(players[0].posX), fix32ToInt(players[0].posY), SPRITE_SIZE(players[0].size_spriteH,players[0].size_spriteV), TILE_ATTR_FULL(players[0].nPal, 0, 0, 0, players[0].index));
			VDP_setSprite(players[1].numSprite, fix32ToInt(players[1].posX), fix32ToInt(players[1].posY), SPRITE_SIZE(players[1].size_spriteH,players[1].size_spriteV), TILE_ATTR_FULL(players[1].nPal, 0, 0, 0, players[1].index) );

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

Re: Problem change sprite size in game

Post by Stef » Fri Jun 10, 2016 8:36 pm

Where are you calling VDP_updateSprites(..) method ? You need it to actually send sprite to VDP.
I guess the tiles are uploaded 1 frame before you update the sprite list in VRAM.

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

Re: Problem change sprite size in game

Post by dub » Sun Jun 12, 2016 9:14 am

Stef wrote:Where are you calling VDP_updateSprites(..) method ? You need it to actually send sprite to VDP.
I guess the tiles are uploaded 1 frame before you update the sprite list in VRAM.
Yes, it's exactly this.

I code like this :

Code: Select all

while(1)
    {
	PL_handleInput();	//sprite changing	
        VDP_updateSprites(10, TRUE);
		VDP_waitVSync();
		
		
    }
I'll try too with "VDP_updateSprites(10, FALSE);"

I certainly made a mistake elsewhere. : Mr. Green:

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

Re: Problem change sprite size in game

Post by Stef » Sun Jun 12, 2016 10:34 am

Using FALSE will send sprites to VDP immediately while TRUE use DMA queue (so sprites are sent at next vblank).
Ideally you should use DMA queue for everything (even from tile loading) but i need to modify some of SGDK methods so they does support DMA queue :)

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

Re: Problem change sprite size in game

Post by dub » Tue Jun 14, 2016 3:39 pm

Thanks a lot :mrgreen:

And I look to change the VDP_loadBMPTileData by VDP_loadTileSet for in game dma use.

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

Re: Problem change sprite size in game

Post by Stef » Tue Jun 14, 2016 6:17 pm

Yeah you should change that as loadBMPData is normally for the bitmap mode ;)

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

Re: Problem change sprite size in game

Post by dub » Sat Jun 25, 2016 10:02 am

I have a question about the spriteengine.

I never test it with the old version, maybe it's normal and I need to test with my code.

I have a metasprite. I use SPRITE player_sprite "sprite/player.png" 4 8 FAST 5
So I have one sprite (32*64pixels) in my sprites array at value 0 equal sprite number 0 and sprite number 1 in the sprite list.

I look the sprite list debug and when my "second" sprites go outside the screen (> 224), it'll become invisible. That's fine. But if I flip the sprite Horizontally, only the visible sprite flip.

Image
You can see his shoes - not flip

I hope I'm clear. :mrgreen:

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

Re: Problem change sprite size in game

Post by Stef » Sat Jun 25, 2016 10:56 am

Is this visible only in the sprite debug stuff ? Or you mean that it was flipped partially out screen then later it showed incorrectly flipped feet ?
Because if you speak about only debug view but screen is correct then that is expected :-)

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

Re: Problem change sprite size in game

Post by dub » Sat Jun 25, 2016 2:00 pm

No, I mean that it was flipped partially out screen then later it showed incorrectly flipped feet. I only use the debug to test the value.

I move down the sprite of sonic, use "SPR_setHFlip(sprites[0], TRUE);" to flip and move up the sprite :
Image

Code: Select all

SPRITE sonic_sprite "sprite/sonic.png" 6 6 0 5
 // init sonic sprite
    sprites[0] = SPR_addSprite(&sonic_sprite, fix32ToInt(posx - camposx), fix32ToInt(posy - camposy), TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
It's the same when I test above the top of the screen.

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

Re: Problem change sprite size in game

Post by Stef » Sat Jun 25, 2016 5:45 pm

Oh ok in this case that is an issue, thanks for reporting :-) What you can in the meantime is to use the SPR_setVisibility(..) method with fast visibility calculation so it won't ignore not visible sprite.

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

Re: Problem change sprite size in game

Post by dub » Sun Jun 26, 2016 7:03 am

Thanks, I'll use that.

Post Reply