Sprite size limitations

SGDK only sub forum

Moderator: Stef

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Sprite size limitations

Post by vnsbr » Mon Feb 11, 2019 2:00 pm

What are the limitations of sprite size? I am trying to make a title screen but my sprite is not showing up. I have tried several combinations of spr_init and spr_init ex, but i am not sure of the supported parameters and if I am hitting a limit.

either of the 2 sprites dont show up completely

title.png is 29x12 and i can convert to background if it helps, pilot.png is 15x17 and I wanted to place after everything (so I think SPRITE is the best way to do that?
title.png
title.png (2.75 KiB) Viewed 7995 times
pilot.png
pilot.png (2.2 KiB) Viewed 7995 times

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

Re: Sprite size limitations

Post by Stef » Mon Feb 11, 2019 3:33 pm

Megadrive doesn't support having more than 320 pixels of sprite on a same scanline, if your title and your character overlap then sprites may be clipped as you reach the pixel limit (232 pixels wide for the title and 120 pixels wide for the character).
Also the sprite engine also has some limit about the maximum number of hardware sprite used by 1 software sprite (16 hardware sprite maximum for 1 software sprite), and here the title alone already eat 24 hardware sprite so you're above this limit too.
Definitely for some large sprites like that (specially the title) you have to use the background, even the character is just above the limit for the number of internal hard sprites (it would work if you can limit its size to 128x128 max).

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Mon Feb 11, 2019 5:13 pm

thanks Stef, as you said I had problems even when they are drawn alone, so it should be hitting the sprite engine limit.

I was planning to have a parallax for the backgrounds, thats why i didnt want to waste much space with it right now, but as I see now the title is way to big :lol:

I will try to design around this limitations.

edit: now that I think about it is that even though pilot is 17x15 i was thinking rescomp would remove most of these tiles since they don't have anything drawn on it.

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Mon Feb 11, 2019 7:22 pm

I don't understand why I am hitting the limit so early. I divided title in 2 sprites to avoid the software limit

now I have:

Code: Select all

SPRITE title1x1         "gfx/title/foreground/1x1title.png" 16 12 FAST 0
SPRITE title2x1         "gfx/title/foreground/2x1title.png" 13 12 FAST 0
SPRITE title_pilot1x1   "gfx/title/foreground/1x1pilot.png" 15 16 FAST 0
 
But I can't show both in the screen, even though there is 80 32x32 sprites available? Aparently only 25 hardware sprites were used in gens as in the screenshot (plus a couple black 8x8 that i am unsure where they are from)
gens.png
gens.png (11.23 KiB) Viewed 7973 times
Here is a small code that reproduces the problem

Code: Select all

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

Sprite *titleScreenSprites[3];

void SetupSystem()
{
    u16 palette[64];

    SYS_disableInts();

    VDP_setScreenWidth320();
    SPR_init();

    VDP_setPaletteColors(0, (u16 *)palette_black, 64);

    SYS_enableInts();

    titleScreenSprites[0] = SPR_addSprite(&title1x1, 0, 0, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    titleScreenSprites[1] = SPR_addSprite(&title2x1, 128, 0, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    titleScreenSprites[2] = SPR_addSprite(&title_pilot1x1, 320 - 120, 240 - 128, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
    memcpy(&palette[32], title1x1.palette->data, 16 * 2);
    memcpy(&palette[48], title2x1.palette->data, 16 * 2);

    VDP_fadeIn(0, (4 * 16) - 1, palette, 20, FALSE);
}

int main()
{
    SetupSystem();

    while (TRUE)
    {
        SPR_update();
        VDP_waitVSync();
    }
    return 0;
}
displays only the title:



even if i draw only part of the title I cant get the pilot to show, like this:

Code: Select all

    
    titleScreenSprites[0] = SPR_addSprite(&title1x1, 0, 0, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    titleScreenSprites[2] = SPR_addSprite(&title_pilot1x1, 320 - 120, 240 - 128, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
    memcpy(&palette[32], title1x1.palette->data, 16 * 2);
    memcpy(&palette[48], title2x1.palette->data, 16 * 2);
    
Attachments
1x1title.png
1x1title.png (1.58 KiB) Viewed 7973 times
1x1pilot.png
1x1pilot.png (1.95 KiB) Viewed 7973 times

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Mon Feb 11, 2019 7:24 pm

i ran out of attachments

here is what is displayd
Gens - Genesis _ SAMPLE PROGRAM                                   11_02_2019 15_56_02.png
Gens - Genesis _ SAMPLE PROGRAM 11_02_2019 15_56_02.png (12.62 KiB) Viewed 7972 times
and the other part of title for the reproduction
2x1title.png
2x1title.png (1.34 KiB) Viewed 7972 times

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

Re: Sprite size limitations

Post by Stef » Mon Feb 11, 2019 7:34 pm

So you only have the character missing ? what is weird is that it's completely missing, shouldn't be the case...
Normally you should have 12+12 (logo) + 16 used sprites (character), here we can see you only have 24 used sprites (logo only) so there is definitely something wrong.

Edit: Oh i see you are using the default SPR_init() method, by default the sprite engine only allocate 384 tiles in VRAM, because you're using very large sprites you need much more here, so use SPR_initEx(80, 640, 640) instead (should be enough).

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Mon Feb 11, 2019 7:43 pm

Yes. It is probably me doing something stupid. But couldnt figure it out yet. 24 (30 or so if you count another black linked sprites) is way below 80. I tried offsetting down the character and no luck too.

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

Re: Sprite size limitations

Post by Stef » Mon Feb 11, 2019 8:24 pm

I edited my message :)

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Tue Feb 12, 2019 12:27 am

hi Stef! yes that did the trick, spot on as always :D
Fusion 3.64 - Genesis - SAMPLE PROGRAM 11_02_2019 21_24_55.png
Fusion 3.64 - Genesis - SAMPLE PROGRAM 11_02_2019 21_24_55.png (10.91 KiB) Viewed 7958 times
256x224 resolution

is there anything i should worry for upping those parameters? like any major drawbacks

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

Re: Sprite size limitations

Post by Stef » Tue Feb 12, 2019 9:27 am

In fact you just allocate more VRAM for the sprite engine (640 tiles on the ~1400 tiles available), also allocating more RAM to unpack the sprite data (consume more RAM but definitely not a issue on MD as you have plenty of RAM).
Having more VRAM allocated for sprites means less VRAM available for the background. But of course you can change the setting when you are in game condition.. So you can shutdown the sprite engine (by calling SPR_end()) then re-init it with SPR_initEx(80, 384, 256) for instance for in-game condition if you need less VRAM for sprites.

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Tue Feb 12, 2019 2:43 pm

Yes thanks for the heads up, turns out i needed righ in the next screen eheh.

I still have a non related problem, if I set the plan_A to scroll, the text is being scrolled together. If i change the text plan to the plan_b i lose text transparency. Plan b does not have transparency?

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

Re: Sprite size limitations

Post by Stef » Tue Feb 12, 2019 3:15 pm

Of course it has, color 0 always let background color to appear. But you need to have plan B behind plan A i guess for what you want ?

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Tue Feb 12, 2019 3:31 pm

How to make sure that plan b is behind? Just the drawing order or some flag?

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

Re: Sprite size limitations

Post by Stef » Tue Feb 12, 2019 4:40 pm

The priority flag in the TILE_ATTR(..) macro you can use with the 'basetile' parameter of VDP_setMapEx(..) or VDP_drawImageEx(..) so you can change priority of the plan (on a tile basis) to HIGH or LOW.

vnsbr
Interested
Posts: 48
Joined: Sun Dec 17, 2017 4:13 pm

Re: Sprite size limitations

Post by vnsbr » Tue Feb 12, 2019 6:02 pm

Code: Select all

        
        VDP_drawImageEx(PLAN_B, &title_background, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
        ind += title_background.tileset->numTile;
        VDP_drawImageEx(PLAN_A, &title_background2, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 0, 0, FALSE, TRUE);
I have tried combinations with TILE_ATTR_FULL(PAL0, TRUE, FALSE, FALSE, ind) and TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind) for both PLANA and B but the outcome is the same (the text background is not transparent)

this is how I draw the test right below:

Code: Select all

        VDP_setTextPalette(PAL1);
        VDP_setTextPlan(PLAN_B);
        VDP_drawText("Start Game", 7, 15);

        VDP_setTextPalette(PAL0);
        VDP_drawText("Options", 7, 17);
        VDP_drawText("Credits", 7, 19);

Post Reply