lundi 2 juin 2008

sprite details and rotations



All in the nds is a bit different from what I expected.
Ok, if you have solved the puzzle it becomes clear that indeed it is what the tuto's and the examples "say". But you have to understand the words in their context. And you can understand it differently depending on what you thought to understand from other programming environments.

So i hope to "say" things a bit more clear, for people starting programming the nds, coming from DIRECTOR or FLASH kind of environments.

So again: sprites are separate from their palettes and now it turns out separate from their rotations!

Example: Say, you have a few sprites, 16 x 16 pixels, 256 colors (so one palette for all)

Then you load these sprites as a sequence: (see also above)

this is an image consisting of 11 sprites: (of course a bit larger then for the nds, :-)






the magenta colour counts as transparent, and the "replay" text consists of three sprites...

You have to initialize it like that:

setSprites(SCREEN_SUB, &gameSprites_tls, gameSprites_tls_size, &gameSprites_pal, gameSprites_pal_size);
(depending on your method, you have to provide screen number, the tiles, tileSize, palette, paletteSize....)

(but the main thing is: all "sprites" are put in at once, this is: put in memory, not yet on the screen.)

now you have to put a piece of this long thing on the screen as "a sprite":

setSprite(SCREEN_SUB, 0 , 0, 0, 200, 10 );
setSprite(SCREEN_SUB, 1 , 1, 0, 200, 30 );
setSprite(SCREEN_SUB, 2 , 1, 0, 200, 50 );
setSprite(SCREEN_SUB, 3 , 2, 3, 200, 70 );
setSprite(SCREEN_SUB, 4 , 2, 2, 200, 90 );

where
the first indicates the screen,
the second: the number (actually in the OAM) of your sprite to be
the third is the index of which rotation is linked to this sprite, some are linked to the same rotation!
the fourth: which piece of the long strip is going to make it to be your sprite
fifth, sixth: x and y

now if you want to play with your sprite: moving it:
you have to refer to the sprite number (inOAM) so this is the second number:

moveSprite(SCREEN_MAIN, 3 , posX, posY ); //or methods like this
so here i move sprite 3, to position posX, posY

but watch carefully now:
rotating the same sprite:
rotateSprite(SCREEN_MAIN, 2 , rotX );
but since sprite 4 is linked to this rotation, it will move to!!!!
actually you change the rotation number 2, and with this the sprites which are linked to it.

so rotateSprite, as a name is not very well chosen: better changeRotation, or something....