How to load a sprite table

Post Reply
Morgawr
Posts: 7
Joined: Tue Jan 27, 2009 8:29 pm

How to load a sprite table

Post by Morgawr » Tue Jan 27, 2009 8:39 pm

Hello everyone.. I was wondering if there is a way to load a whole sprite table and then separate sprites inside the game itself... what I mean is (I don't know if it's really called sprite table >.<) load an image with all the frames of different sprites (like different ways a character can walk) and then "disassemble" it in different sprites to load in memory and then display them separated... is it possible? how can I do it? I'm trying to work something out with oamTables and stuff like that but I can't get it right, please help thanks ;)

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: How to load a sprite table

Post by Sylus101 » Wed Jan 28, 2009 12:54 am

I'm sure if I'll be able to answer this correctly, but I can try. If you're starting with a vertical framestrip of a sprite, lets say 16 x 16 in one frame and 10 frames long, what you'll have once grit (or whatever conversion program you use) converts the image is an array that in which each 256 byte chunk is each frame. So lets say in this case you have mysprite[2560], and we're looking at the libnds example for SimpleSprite.

Since we have the gfx pointer already setup, all we need to do is write the correct frame into that memory location. We could use DMA instead of the for loop that the example uses to do it like this:

Code: Select all

//set these up so we're not using magic numbers in our code
int length = 16;
int width = 16;
int frame = 4;

DC_FlushRange(mysprite + length*width*frame, length*width);
dmaCopy(mysprite + length*width*frame, gfx, length*width);
I'm not sure if you're looking for something more complicated than this, but it's a start. Keep in mind, you'd need to handle the palette too...
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

Morgawr
Posts: 7
Joined: Tue Jan 27, 2009 8:29 pm

Re: How to load a sprite table

Post by Morgawr » Wed Jan 28, 2009 4:30 pm

Sylus101 wrote:I'm sure if I'll be able to answer this correctly, but I can try. If you're starting with a vertical framestrip of a sprite, lets say 16 x 16 in one frame and 10 frames long, what you'll have once grit (or whatever conversion program you use) converts the image is an array that in which each 256 byte chunk is each frame. So lets say in this case you have mysprite[2560], and we're looking at the libnds example for SimpleSprite.

Since we have the gfx pointer already setup, all we need to do is write the correct frame into that memory location. We could use DMA instead of the for loop that the example uses to do it like this:

Code: Select all

//set these up so we're not using magic numbers in our code
int length = 16;
int width = 16;
int frame = 4;

DC_FlushRange(mysprite + length*width*frame, length*width);
dmaCopy(mysprite + length*width*frame, gfx, length*width);
I'm not sure if you're looking for something more complicated than this, but it's a start. Keep in mind, you'd need to handle the palette too...
this is very useful, really thanks.. for the palette though... can't I just use the whole palette (like the originalSpritePal) that contains ALL the code of the sprites? will it work? I'm getting a lot of troubles trying to figure this stuff out because the examples and tutorials, even though they provide a really nice theoretical basis, they all have different examples and the documentation is really messed up badly @_@

dovoto
Developer
Posts: 43
Joined: Fri Aug 12, 2005 10:01 pm
Contact:

Re: How to load a sprite table

Post by dovoto » Sat Jan 31, 2009 12:20 am

I added an example to libnds which does nearly exactly this. It uses grit to parse the frames though.

Its in the svn and will be out with next libnds release (which is forthcomming).

examples/nds/Graphics/Sprites/animate_simple

http://devkitpro.svn.sourceforge.net/vi ... te_simple/

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests