Page 1 of 1

Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 3:24 am
by POLYGAMe
Hi again,

I have got to the stage where I want to start adding sprites. I believe the VDP handles the tiles for me and I don't have to allocate tile memory like I do with the backgrounds, right?

Anyway, the game works fine but when I add the car in, it seems part of the tileset on frame four of my road is being written over. How would I fix this? You can see in the bottom corners.

Here's the code for setting up the BG:

Code: Select all

 // DRAW SKY
    u16 iSkyTileSet;
    iSkyTileSet = TILE_USERINDEX;
    VDP_loadTileSet(sky_tropical.tileset, iSkyTileSet, FALSE);
    Map *map = unpackMap(sky_tropical.map, NULL);
    VDP_setMapEx(APLAN, map, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, iSkyTileSet), 0, 0, 0, 0, 64, 12);

    // DRAW ROAD
    u16 iRoadTileSet;
    iRoadTileSet = TILE_USERINDEX + sky_tropical.tileset->numTile;
    VDP_loadTileSet(road_tropical.tileset, iRoadTileSet, FALSE);
    Map *map2 = unpackMap(road_tropical.map, NULL);
    VDP_setMapEx(BPLAN, map2, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, iRoadTileSet), 0, 0, 0, 0, 64, 64);
And the code for setting up sprite:

Code: Select all

// Init buggy sprite
    SPR_initSprite(&sprites[0], &sprite_buggy, 128, 170, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
    SPR_update(sprites, 1);
I'm going off the sprite demo but not entirely sure what's going on under the hood. lol.

EDIT: I have attached a screen print from GENS debug plane B

Re: Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 4:03 am
by POLYGAMe
I tried manually allocating but the following didn't work, either:

Code: Select all

   u16 iBuggyTileSet;
    iBuggyTileSet = TILE_USERINDEX + sky_tropical.tileset->numTile + road_tropical.tileset->numTile;
    SPR_setVRAMTileIndex(&sprite_buggy,iBuggyTileSet);
Gave me the same result...

Re: Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 4:31 am
by POLYGAMe
Ok, it turns out I'm running out of tiles. I'm going to have to optimise my graphics. Might cut cars in half etc and flip the sprites. I also just realised that my road image isn't set up properly so the flipped duplicated tiles won't be detected and utilised...

Re: Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 11:02 am
by Stef
Yeah i was to propose you to check if you are not running out of VRAM ;) that is the classic issue we have when that is the case.

Re: Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 6:02 pm
by POLYGAMe
Hehe the joys of classic systems.

Just looking in gens and my flipped tiles are showing up as unique tiles. Is there a way to fix this? By cutting those I'd save half of my VRAM :)

Re: Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 8:45 pm
by Stef
Try to download the last rescomp tool directly from the github repository, I believe I fixed this issue few time ago !

Re: Garbled GFX when I add sprite

Posted: Mon Mar 28, 2016 9:30 pm
by POLYGAMe
Stef wrote:Try to download the last rescomp tool directly from the github repository, I believe I fixed this issue few time ago !
Will do. Thanks!

Re: Garbled GFX when I add sprite

Posted: Sun Apr 03, 2016 4:08 pm
by Stef
Unlike i said previously, i didn't update the rescomp in github as there are too many changes to commit that will break everything else.
You will have to wait for the next "official" version of SGDK to finally have this fixed, sorry !

Re: Garbled GFX when I add sprite

Posted: Mon Jun 20, 2016 5:28 am
by ronin68k
Hi, guys! Sorry if i posted it to a wrong place, but i think, i have almost similar problem.
(and i think the problem is me)

Im trying to draw complete Mortal Kombat arena background and it shows me this...
Image

I presume, original Mortal Kombat game uses partical BG drawing, but since im noob, i can't do the same :lol:
is this SGDK problem or just me?

here is the rom with sources

Thank y'all, luw y'all <3

Re: Garbled GFX when I add sprite

Posted: Mon Jun 20, 2016 8:36 am
by dub
I don't know if you post in the wrong place :mrgreen:

But for your gfx problem. You have by default a plan size of 64 tiles. So your picture must be 64 tiles * 8 pixels = 512 pixels width. So the last pixel will be drawn at the beginning of your plan over the existing image.

You're picture size is 800+ pixels. So you can change the plan size to 128tiles (1024 pixels) with VDP_setPlanSize( 128, 32); You can see the plan (A / B) with gensKMod in CPU -> Debug -> Plan

Code: Select all

int main()
{
    u16 palette[64];

    // disable interrupt when accessing VDP
    SYS_disableInts();
    // initialization
    VDP_setScreenWidth320();
	
	
				VDP_setPlanSize( 128, 32);

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

    // set all palette to black
    VDP_setPaletteColors(0, (u16*) palette_black, 64);
    ....
    ....

Re: Garbled GFX when I add sprite

Posted: Mon Jun 20, 2016 10:35 am
by ronin68k
It solved the problem! :D
Thanks, my friend! <3