Differentiate a sprite from another during comparisons [SOLVED]

SGDK only sub forum

Moderator: Stef

Post Reply
User avatar
cloudstrifer
Interested
Posts: 23
Joined: Mon Feb 19, 2018 7:31 pm

Differentiate a sprite from another during comparisons [SOLVED]

Post by cloudstrifer » Thu Mar 29, 2018 7:36 pm

Hi!

I do not know how to differentiate one sprite from another during comparisons.

How can I differentiate between char01_sprite and item_sprite in a FOR LOOP?

Code: Select all

    // init sprites
    arrSprites[0] = SPR_addSprite(&char01_sprite, 160, 160, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));    
    arrSprites[1] = SPR_addSprite(&item_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
    arrSprites[2] = SPR_addSprite(&item_sprite, 16, 128, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
    arrSprites[3] = SPR_addSprite(&item_sprite, 32, 128, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
Last edited by cloudstrifer on Wed Apr 04, 2018 2:09 pm, edited 3 times in total.

Miquel
Very interested
Posts: 291
Joined: Sat Jul 30, 2016 12:33 am

Re: Differentiate one sprite from another during comparisons

Post by Miquel » Thu Mar 29, 2018 9:04 pm

For all I known all videogames in existence have a list of Actors/Entities/Objects in cpu ram with data to make them a reality. In this data can be identifiers, pointers, lists, arrays, whatever to identify and classify them.

So one thing is what is displayed in screen, another thing is the data you have in ram that lets you display those sprites.
To my knowledge it was 14 "spiders" of different sizes.
By the way, at high speeds stars truly become lines like in the movies, do there are a couple of differences. Can you guess which are?

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

Re: Differentiate one sprite from another during comparisons

Post by Stef » Fri Mar 30, 2018 9:23 am

Why not using separate variable to store you different kind of sprite ?

Code: Select all

Sprite* charSprite;
Sprite* itemSprites[10];

charsprite = SPR_addSprite(&char01_sprite, 160, 160, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
itemSprites[0] = SPR_addSprite(&item_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
itemSprites[1] = SPR_addSprite(&item_sprite, 16, 128, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
itemSprites[2] = SPR_addSprite(&item_sprite, 32, 128, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));

User avatar
cloudstrifer
Interested
Posts: 23
Joined: Mon Feb 19, 2018 7:31 pm

Re: Differentiate one sprite from another during comparisons

Post by cloudstrifer » Tue Apr 03, 2018 1:23 pm

I have some issues with this code below.

Code: Select all

Sprite* charSprites[2];
Sprite* itemSprites[10];
Sprite* enemySprites[10];

charSprites[0] = SPR_addSprite(&char01_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
charSprites[1] = SPR_addSprite(&char02_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));

itemSprites[0] = SPR_addSprite(&item01_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
itemSprites[1] = SPR_addSprite(&item01_sprite, 16, 128, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
itemSprites[2] = SPR_addSprite(&item02_sprite, 32, 128, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));


enemySprites[0] = SPR_addSprite(&enemy01_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
enemySprites[1] = SPR_addSprite(&enemy02_sprite, 16, 112, TILE_ATTR(PAL2, FALSE, FALSE, FALSE));
Thank you!
Last edited by cloudstrifer on Tue Apr 03, 2018 1:51 pm, edited 1 time in total.

User avatar
Sik
Very interested
Posts: 684
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Differentiate one sprite from another during comparisons

Post by Sik » Tue Apr 03, 2018 1:51 pm

...what issues?
Sik is pronounced as "seek", not as "sick".

User avatar
cloudstrifer
Interested
Posts: 23
Joined: Mon Feb 19, 2018 7:31 pm

Re: Differentiate one sprite from another during comparisons

Post by cloudstrifer » Tue Apr 03, 2018 1:59 pm

I have 2 comparations one to get itens and other to collide, block passage.

But my itens have collisions.

All sprites have only one index?


Code: Select all

for(int y = 0; y <= sizeof(itemSprites) -1; y++) {
    //do get item
}


for(int y = 0; y <= sizeof(objectSprites) -1; y++) {
    //do collisions
}

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

Re: Differentiate a sprite from another during comparisons

Post by Stef » Wed Apr 04, 2018 8:55 am

I'm not sure to understand what is your problem...
You want to make collision between which kind of object ?

Miquel
Very interested
Posts: 291
Joined: Sat Jul 30, 2016 12:33 am

Re: Differentiate a sprite from another during comparisons

Post by Miquel » Wed Apr 04, 2018 1:11 pm

Let me try one last time: no game uses video/graphical sprites for stuff like collisions or any other computing duty.
To my knowledge it was 14 "spiders" of different sizes.
By the way, at high speeds stars truly become lines like in the movies, do there are a couple of differences. Can you guess which are?

User avatar
cloudstrifer
Interested
Posts: 23
Joined: Mon Feb 19, 2018 7:31 pm

Re: Differentiate a sprite from another during comparisons [SOLVED]

Post by cloudstrifer » Wed Apr 04, 2018 2:08 pm

Sorry guys, the problem is sizeof function, my mistake. :oops:

Thank you!

Code: Select all

int size = (sizeof(itemSprites)/sizeof(itemSprites[0])) -1;

for(int y = 0; y <= size; y++) {
    //do get item
}

int size = (sizeof(objectSprites)/sizeof(objectSprites[0])) -1;

for(int y = 0; y <= size; y++) {
    //do collisions
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest