Page 1 of 1

Differentiate a sprite from another during comparisons [SOLVED]

Posted: Thu Mar 29, 2018 7:36 pm
by cloudstrifer
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));

Re: Differentiate one sprite from another during comparisons

Posted: Thu Mar 29, 2018 9:04 pm
by Miquel
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.

Re: Differentiate one sprite from another during comparisons

Posted: Fri Mar 30, 2018 9:23 am
by Stef
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));

Re: Differentiate one sprite from another during comparisons

Posted: Tue Apr 03, 2018 1:23 pm
by cloudstrifer
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!

Re: Differentiate one sprite from another during comparisons

Posted: Tue Apr 03, 2018 1:51 pm
by Sik
...what issues?

Re: Differentiate one sprite from another during comparisons

Posted: Tue Apr 03, 2018 1:59 pm
by cloudstrifer
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
}

Re: Differentiate a sprite from another during comparisons

Posted: Wed Apr 04, 2018 8:55 am
by Stef
I'm not sure to understand what is your problem...
You want to make collision between which kind of object ?

Re: Differentiate a sprite from another during comparisons

Posted: Wed Apr 04, 2018 1:11 pm
by Miquel
Let me try one last time: no game uses video/graphical sprites for stuff like collisions or any other computing duty.

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

Posted: Wed Apr 04, 2018 2:08 pm
by cloudstrifer
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
}