Troubles with sprites (new version SGDK)

SGDK only sub forum

Moderator: Stef

alko
Very interested
Posts: 153
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Troubles with sprites (new version SGDK)

Post by alko » Mon Jul 04, 2016 4:35 pm

Compile by SGDK 1.12

SPR_init(300);

Image

Compile by SGDK 1.2

SPR_init(80, 640, 640); or SPR_init(80, 320, 320); or SPR_init(80, 0, 0); or SPR_init(32, 0, 0); .... etc. :

Image

what am I doing wrong :?:
Image

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

Re: Troubles with sprites (new version SGDK)

Post by Stef » Mon Jul 04, 2016 8:44 pm

I think you are hitting the 16 hard sprites limit of the new SGDK 1.2, previous allowed 20 VDP sprites by meta sprite, now you are limited to 16 max. It was necessary for some internals tweaks. Honestly I was thinking nobody will use a so large sprite :-p
I guess you need to split in 2 now :-/

alko
Very interested
Posts: 153
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Troubles with sprites (new version SGDK)

Post by alko » Thu Jul 07, 2016 8:36 am

before:
ufo.png 176*64
--
SPRITE ufo "ufo.png" 22 8 -1


after:
ufo1.png 88*64
ufo2.png 88*64
--
SPRITE ufo1 "ufo1.png" 11 8 -1
SPRITE ufo2 "ufo2.png" 11 8 -1

may be necessary to split in 4 ?... Very inconveniently turns out. Сumbersome.
Image

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

Re: Troubles with sprites (new version SGDK)

Post by Stef » Thu Jul 07, 2016 1:21 pm

It turns out that your original sprite still fit in the limit : 176*64 could be done in 6*2 = 12 sprites of 32x32 pixels.
So you're below the 16 sprites limit. Are you doing something special with that sprite ??
Can you provide me a simple sample test which replicate the problem ? that would help me in solving this issue :)

alko
Very interested
Posts: 153
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Troubles with sprites (new version SGDK)

Post by alko » Thu Jul 07, 2016 4:32 pm

Stef wrote: Are you doing something special with that sprite ??
Just adding to scene and changing coordinates.

Code: Select all

int main()
{

    SYS_disableInts();

    VDP_setScreenWidth320();
    VDP_setScreenHeight240();

    //  JOY_setEventHandler(joyEvent);

    zastavka();

    init_game();

    SYS_enableInts();
    while(TRUE)
    {
        //    handleInput();

        u32 current =  getTimer(0, FALSE);
        u32 elapsed = current - previous;
        previous = current;
        lag += elapsed;


        while (lag >= 2000)
        {


            update_game();
            lag -= 2000;
        }

        SPR_update(sprites, 80);

        VDP_waitVSync();
    }

    return 0;
}

Code: Select all

void init_game()
{
   // VDP_resetSprites();
    ind = TILE_USERINDEX;
    VDP_setVerticalScroll(PLAN_A,0);
    VDP_setVerticalScroll(PLAN_B,0);

    VDP_clearPlan	(PLAN_A,1);
    VDP_clearPlan	(PLAN_B,1);

    SPR_init(16, 0, 0);


    VDP_setPalette(PAL0, sky.palette->data);
    VDP_setPalette(PAL1, ufo.palette->data);
    VDP_setPalette(PAL2, city.palette->data);

    VDP_waitVSync();

    VDP_drawImageEx(PLAN_B, &sky, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind),0, 0, FALSE, TRUE);
    ind += sky.tileset->numTile;

    VDP_drawImageEx(PLAN_B, &water, TILE_ATTR_FULL(PAL0, TRUE, FALSE, FALSE, ind),0, 22, FALSE, TRUE);
    ind += water.tileset->numTile;

    VDP_drawImageEx(PLAN_A, &city, TILE_ATTR_FULL(PAL2, TRUE, FALSE, FALSE, ind),0, 0, FALSE, TRUE);
    ind += city.tileset->numTile;



    sprites[0] = SPR_addSprite( &ufo , 350, 0, TILE_ATTR(PAL1, FALSE, FALSE, FALSE));
    sprites[50] = SPR_addSprite( &plant , 0, 0, TILE_ATTR(PAL1, FALSE, FALSE, FALSE));
   // sprites[51] = SPR_addSprite( &plant , 350, 0, TILE_ATTR(PAL1, FALSE, FALSE, TRUE));
   // sprites[52] =SPR_addSprite( &plant , 350, 0, TILE_ATTR(PAL1, FALSE, FALSE, TRUE));

    u16 i;
    for(i=1; i<30; i++)
    {
        if(i%2==0)sprites[i]=SPR_addSprite( &seed , 350, 0, TILE_ATTR(PAL1, FALSE, FALSE, FALSE));
        else sprites[i]=SPR_addSprite( &seed , 350, 0, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
    }



    for(i=0; i<32; i++)
    {
        seedposx[i]=random()%1000;
        seedposy[i]=100;
        seedposdy[i]=random()%2+1;
    }

    SND_startPlay_PCM(ME, sizeof(ME), SOUND_RATE_22050, SOUND_PAN_CENTER , 0);
    startTimer(0);
    previous =  getTimer(0, 0);


}

Code: Select all

u32 previous ;
u32 lag = 0;

int planty=400;
int planty1=520;
int planty2=480;

int ufoy=320;
int ufox=650;
u16 state=0;
int mayatnikdx=1;
int mayatnik2=1;
u16 timer;
int seedposx[32];
int seedposy[32];
int seedposdy[32];
void update_game()
{
    if(state==0)
    {
        VDP_setPalette(PAL0, sky.palette->data);
        VDP_setPalette(PAL1, ufo.palette->data);
        VDP_setPalette(PAL2, city.palette->data);

        mayatnikdx+=8;
        SPR_setPosition(sprites[0],ufox/2, ufoy/8+(cosFix16(mayatnikdx)>>4));
         ufox=ufox-1;
        //  ufoy=ufoy-1;
        if(ufox/2<80)
        {
            state=1;
            timer=400;
        }
    }
    if(state==1)
    {
        if(timer>0)timer--;
        else
        {
            state=2;
            timer=800;
        }

        u16 i;
        for(i=1; i<30; i++)
        {
            mayatnik2++;
            SPR_setPosition(sprites[i], 155+(cosFix16((mayatnik2>>1)+seedposx[i])>>1),seedposy[i] );
            seedposy[i]+=seedposdy[i];
            if(seedposy[i]>190)
            {
                seedposy[i]=80;
                seedposdy[i]=random()%2+1;
            }

        }


        mayatnikdx+=8;
        SPR_setPosition(sprites[0], ufox/2+(sinFix16(mayatnikdx)>>4), ufoy/8+(cosFix16(mayatnikdx)>>4));

    }

    if(state==2)
    {
        u16 i;
        for(i=1; i<30; i++)
        {
            if(seedposy[i]<200)
            {
                mayatnik2++;
                seedposy[i]+=seedposdy[i];
                SPR_setPosition(sprites[i], 155+(cosFix16((mayatnik2>>1)+seedposx[i])>>1),seedposy[i] );
            }
        }

        mayatnikdx+=8;
        SPR_setPosition(sprites[0], ufox/2, ufoy/8+(cosFix16(mayatnikdx)>>4));
        ufoy-=2;
        ufox--;

        if(planty/2>52)
        {
            planty--;
            SPR_setPosition(sprites[50], 110+random()%3, planty/2);
        }

        if(planty1/2>80)
        {
            planty1--;
            SPR_setPosition(sprites[51], 30+random()%3, planty1/2);
        }
        if(planty2/2>70)
        {
            planty2--;
            SPR_setPosition(sprites[52], 230+random()%3, planty2/2);
        }

        if(timer>0)timer--;
        else
        {
            state=3;
             VDP_resetSprites();
            VDP_clearPlan	(PLAN_A,1);
            VDP_clearPlan	(PLAN_B,1);

            VDP_setScrollingMode(HSCROLL_PLANE, VSCROLL_PLANE);

            ind = TILE_USERINDEX;
            VDP_setPalette(PAL0, mask.palette->data);
            VDP_setPalette(PAL1, earth1.palette->data);
            VDP_drawImageEx(PLAN_A, &mask, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind),2, 8, FALSE, TRUE);
            ind += mask.tileset->numTile;
            VDP_drawImageEx(PLAN_B, &earth1, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind),2, 8, FALSE, TRUE);
            ind += earth1.tileset->numTile;
        }
    }
    if(state==3)
    {

    }
if(state<=2)    wave_effect();
}
Image

astrofra
Interested
Posts: 27
Joined: Sun Dec 14, 2014 8:50 am
Location: Orleans | France
Contact:

Re: Troubles with sprites (new version SGDK)

Post by astrofra » Tue Jul 26, 2016 2:56 am

Hi Alko,
Nice to see another demoscene dude around here :)
SPR_update(sprites, 80);
Can you check if this function is still asking parameters this way ?

Maybe you could share the whole archive of your demo (even privately).
It's not like someone is going to steal your source code :)
640 polygons are enough for everyone.

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

Re: Troubles with sprites (new version SGDK)

Post by Stef » Tue Jul 26, 2016 9:05 am

Oh sorry i forgot to reply to your last post Alko, in fact i missed it... As astrofa said, the API changed a bit and SPR_update() doesn't take any parameter now. Still that shouldn't be the problem here, I will try to replicate your issue.

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

Re: Troubles with sprites (new version SGDK)

Post by dub » Sun Jul 31, 2016 2:36 pm

Reading your code, I realized one thing. There is an issue in the new version of sgdk, Stef will look at it.
The sprite engine have some problems when you use meta-sprite outside of the screen.

you init your sprite at 350.

So, you can add this :

Code: Select all

sprites[0] = SPR_addSprite( &ufo , 350, 0, TILE_ATTR(PAL1, FALSE, FALSE, FALSE));
 SPR_setVisibility( sprites[0], AUTO_FAST);
I think it will solve your problem. :mrgreen:

you can see here :
viewtopic.php?f=19&t=2457

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

Re: Troubles with sprites (new version SGDK)

Post by Stef » Sun Jul 31, 2016 8:16 pm

Fixed in my WIP, i plan to do a quick release soon, hoping it will the issue alko experienced here.

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Troubles with sprites (new version SGDK)

Post by Hik » Sun Aug 14, 2016 11:20 pm

I'm also ajusting to the changes in the sprite engine. I still have some things to fix with the code I've got ,
mostly "incompatible types in assignment" errors and some declaration errors.

I still have a lot to learn when it comes to programming but it helps that I'm really interested in the Mega Drive/Genesis.
It compels me to learn more and adapt. I'm focused on it since it's my only console ,I only have it and the PC.

I'm a very good artist so I prefer to get the graphics working first. But now its been a bit of a while since I worked on this code
so it would be great to have some pointers on how to work with it. I know about the documentation but I'm not sure about some
of the numbers like with the SPR_init() function which numbers would be appropriate there.

alko
Very interested
Posts: 153
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Troubles with sprites (new version SGDK)

Post by alko » Mon Aug 15, 2016 5:13 am

astrofra wrote: Maybe you could share the whole archive of your demo (even privately).
Ok. Today I will share source
Image

alko
Very interested
Posts: 153
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Troubles with sprites (new version SGDK)

Post by alko » Mon Aug 15, 2016 6:26 pm

but I started redo to old version SGDK.
:oops:
https://www.dropbox.com/s/c5a3en57m9v592n/UFO.rar?dl=0
Image

alko
Very interested
Posts: 153
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Troubles with sprites (new version SGDK)

Post by alko » Mon Aug 15, 2016 6:40 pm

dub wrote: I think it will solve your problem. :mrgreen:
good
I check out this method later.
Image

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Troubles with sprites (new version SGDK)

Post by Hik » Sun Sep 18, 2016 10:27 pm

I keep getting incompatible types in assignment errors when using SPR_addSprite on the latest version of SGDK.

Can someone help fix that?

Grind
Very interested
Posts: 64
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Troubles with sprites (new version SGDK)

Post by Grind » Sun Sep 18, 2016 10:49 pm

Post code and error log?

Maybe confusing Sprite with SpriteDefinition or need to pass a reference like &mySpriteDef.

Post Reply