gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > How to access different parts of a larger sprite?

#155609 - J1M - Thu May 01, 2008 6:57 pm

Hi, I am making a Dr. Mario clone to learn about programming on the DS. I have looked at a few tutorials, and I can load in a background, a sprite, and move it around.

I can't seem to find a tutorial on how to do the following, however:

I have a 32x32 sprite with 16 8x8 images on it. I want to use load in this larger sprite and reference different parts of it for each virus or pill capsule. I can load the whole 32x32 image but when I set it to just show 8x8 I can't figure out how to show anything other than the top left 8x8 pixels.

If needed I can upload a .png of my sprite, but this seems to be something really basic like SpriteObject->IndexNum = 3; or something

#155610 - SevenString - Thu May 01, 2008 7:22 pm

J1M wrote:
Hi, I am making a Dr. Mario clone to learn about programming on the DS. I have looked at a few tutorials, and I can load in a background, a sprite, and move it around.

I can't seem to find a tutorial on how to do the following, however:

I have a 32x32 sprite with 16 8x8 images on it. I want to use load in this larger sprite and reference different parts of it for each virus or pill capsule. I can load the whole 32x32 image but when I set it to just show 8x8 I can't figure out how to show anything other than the top left 8x8 pixels.

If needed I can upload a .png of my sprite, but this seems to be something really basic like SpriteObject->IndexNum = 3; or something


For technical reasons involving sprite memory layout, it is much easier to organize your small sprites in your original image as a vertical strip, and then once you convert/load it into OBJ sprite RAM, you can then create each 8x8 sprite with an offset address that points the smaller sprite image you want.

For 8x8x8bit (256col), the OBJ address of the individual sprite would be:

objSpriteAddress + (pillNumber << 6)

and for 8x8x4bit (16col), the address of the sprite would be:

objSpriteAddress + (pillNumber << 5)


EDITED FOR ACCURACY BECAUSE I HAD A BRAIN FART RE 2D MAPPING...
_________________
"Artificial Intelligence is no match for natural stupidity."


Last edited by SevenString on Thu May 01, 2008 11:31 pm; edited 1 time in total

#155631 - tepples - Thu May 01, 2008 10:56 pm

SevenString wrote:
For technical reasons involving sprite memory layout and how the hw sprite rendering is done, you can't really tell the sprite system to treat a subregion of a larger sprite as a smaller sprite, at least in the x direction.

You can if you set the sprite sheet to 2D mode, as Kirby: Nightmare in Dream Land does. Or you can if you're always taking an 8-pixel-tall slice, as would be done in a Tetris clone or a Dr. Mario clone; the 1D vs. 2D sprite sheet bit has a noticeable effect only for sprites taller than 8 pixels.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#155635 - SevenString - Thu May 01, 2008 11:32 pm

tepples wrote:
SevenString wrote:
For technical reasons involving sprite memory layout and how the hw sprite rendering is done, you can't really tell the sprite system to treat a subregion of a larger sprite as a smaller sprite, at least in the x direction.

You can if you set the sprite sheet to 2D mode, as Kirby: Nightmare in Dream Land does. Or you can if you're always taking an 8-pixel-tall slice, as would be done in a Tetris clone or a Dr. Mario clone; the 1D vs. 2D sprite sheet bit has a noticeable effect only for sprites taller than 8 pixels.


Consider my original post "temporary insanity". I seem to have had a brain-fart re. 2d sprite mapping.
_________________
"Artificial Intelligence is no match for natural stupidity."