NightFox’s Lib
|
Functions to load and handle 256 color sprites. More...
Data Structures | |
struct | NF_TYPE_SPR256GFX_INFO |
Struct that holds information about sprite graphics in RAM. More... | |
struct | NF_TYPE_SPR256PAL_INFO |
Struct that holds information about sprite palettes in RAM. More... | |
struct | NF_TYPE_SPR256VRAM_INFO |
Struct that holds information about sprite graphics in VRAM. More... | |
struct | NF_TYPE_SPRPALSLOT_INFO |
Struct that holds information about sprite palettes in VRAM. More... | |
struct | NF_TYPE_SPRITEOAM_INFO |
Struct that defines OAM information. More... | |
struct | NF_TYPE_SPRVRAM_INFO |
Struct with information of sprite allocation in VRAM. More... | |
Macros | |
#define | NF_SLOTS_SPR256GFX 256 |
Maximum number of slots of 256 color sprites. | |
#define | NF_SLOTS_SPR256PAL 64 |
Maximum number of slots of palettes of 256 color sprites. | |
Functions | |
void | NF_InitSpriteBuffers (void) |
Initialize library to load files from the filesystem to create 256 color sprites. More... | |
void | NF_ResetSpriteBuffers (void) |
Reset state used for 256 color sprites loaded from FAT. More... | |
void | NF_InitSpriteSys (int screen,...) |
Initialize sprite system in the specified screen. More... | |
void | NF_LoadSpriteGfx (const char *file, u32 id, u32 width, u32 height) |
Load sprite graphics from the filesystem to RAM to use it later. More... | |
void | NF_UnloadSpriteGfx (u32 id) |
Delete from RAM the graphics of the selected slot and mark it as free. More... | |
void | NF_LoadSpritePal (const char *file, u32 id) |
Load a palette from the filesystem to RAM to be used for a sprite. More... | |
void | NF_UnloadSpritePal (u32 id) |
Delete the selected palette from RAM and mark it as free. More... | |
void | NF_VramSpriteGfx (int screen, u32 ram, u32 vram, bool keepframes) |
Copy a graphics object from RAM to VRAM of the selected screen to be used as a sprite. More... | |
void | NF_FreeSpriteGfx (int screen, u32 id) |
Delete from VRAM the graphics object of the selected slot and a screen. More... | |
void | NF_VramSpriteGfxDefrag (int screen) |
Defragments the free VRAM used for sprite graphics. More... | |
void | NF_VramSpritePal (int screen, u32 id, u32 slot) |
Copy the palette from RAM to a slot of extended palettes in VRAM. More... | |
void | NF_CreateSprite (int screen, u32 id, u32 gfx, u32 pal, s32 x, s32 y) |
Create a sprite with the specified ID in the selcted screen. More... | |
void | NF_DeleteSprite (int screen, u32 id) |
Delete the selected sprite ID from the specified screen. More... | |
void | NF_SpriteOamSet (int screen) |
Copy data from the shadow OAM used by NFLib to the real OAM of libnds. More... | |
void | NF_SpriteSetPalColor (int screen, u32 pal, u32 number, u32 r, u32 g, u32 b) |
Changes a color of a sprite palette in the specified screen. More... | |
void | NF_SpriteEditPalColor (int screen, u32 pal, u32 number, u32 r, u32 g, u32 b) |
Changes the value of one color in a sprite palettes of the specified screen. More... | |
void | NF_SpriteUpdatePalette (int screen, u32 pal) |
Updates a sprite palette in VRAM with the copy in RAM of it. More... | |
void | NF_SpriteGetPalColor (int screen, u32 pal, u32 number, u8 *r, u8 *g, u8 *b) |
Gets the RGB value of a color of a sprites palette in RAM. More... | |
Variables | |
char * | NF_BUFFER_SPR256GFX [NF_SLOTS_SPR256GFX] |
Buffers to hold 256 color sprite graphics. | |
char * | NF_BUFFER_SPR256PAL [NF_SLOTS_SPR256PAL] |
Buffers to hold 256 color sprite palettes. | |
NF_TYPE_SPR256GFX_INFO | NF_SPR256GFX [NF_SLOTS_SPR256GFX] |
Information of all sprite graphics in RAM. | |
NF_TYPE_SPR256PAL_INFO | NF_SPR256PAL [NF_SLOTS_SPR256PAL] |
Information of all palettes in RAM. | |
NF_TYPE_SPR256VRAM_INFO | NF_SPR256VRAM [2][128] |
Information of all sprite graphics in VRAM. | |
NF_TYPE_SPRPALSLOT_INFO | NF_SPRPALSLOT [2][16] |
Information of all palettes in VRAM. | |
NF_TYPE_SPRITEOAM_INFO | NF_SPRITEOAM [2][128] |
OAM information of all sprites. | |
NF_TYPE_SPRVRAM_INFO | NF_SPRVRAM [2] |
Information of sprite allocation in VRAM of both screens. | |
Functions to load and handle 256 color sprites.
void NF_CreateSprite | ( | int | screen, |
u32 | id, | ||
u32 | gfx, | ||
u32 | pal, | ||
s32 | x, | ||
s32 | y | ||
) |
Create a sprite with the specified ID in the selcted screen.
You have to select the graphics object to use, as well as the palette to use. You also have to select the initial coordinates of the sprite.
Example:
screen | Screen (0 - 1). |
id | Sprite ID (0 - 127). |
gfx | Graphics object ID (0 - 127). |
pal | Palette (0 - 15). |
x | X coordinate. |
y | Y coordinate. |
void NF_DeleteSprite | ( | int | screen, |
u32 | id | ||
) |
Delete the selected sprite ID from the specified screen.
The graphics and palette used by the sprite won't be deleted from VRAM.
Example:
screen | Screen (0 - 1). |
id | Sprite ID (0 - 127). |
void NF_FreeSpriteGfx | ( | int | screen, |
u32 | id | ||
) |
Delete from VRAM the graphics object of the selected slot and a screen.
You mustn't delete the graphics while a sprite is using them.
Example:
screen | Screen (0 - 1). |
id | VRAM slot (0 - 127). |
void NF_InitSpriteBuffers | ( | void | ) |
Initialize library to load files from the filesystem to create 256 color sprites.
Use this function once before loading any sprite from FAT. Don't call it more than once.
Example:
void NF_InitSpriteSys | ( | int | screen, |
... | |||
) |
Initialize sprite system in the specified screen.
The VRAM mapping parameter is optional, if you don’t set it, 64 is set by default. You can use up to 1024 chunks of 64 bytes (64 mapping mode) or 128 bytes (128 mapping mode) and 16 palettes. The use of mode 64 limits the amount of usable VRAM to 64 KB. When using mode 128, 8x8 pixels sprites can't be used.
Example:
screen | Screen (0 - 1). |
... | VRAM mapping mode (64 or 128). |
void NF_LoadSpriteGfx | ( | const char * | file, |
u32 | id, | ||
u32 | width, | ||
u32 | height | ||
) |
Load sprite graphics from the filesystem to RAM to use it later.
You must specify the filename without extension. You must use the ".img" extension in the filename of you sprite graphics file. You must select the RAM slot to hold the graphics (0 to 255), and the graphics sizes. If it's an animated sprite, put the size in pixels of first frame.
There are 256 available slots, as specified in:
Example:
file | File name without extension. |
id | Slot number (0 - 255). |
width | Width of the graphics object (in pixels). |
height | Height of the graphics object (in pixels). |
void NF_LoadSpritePal | ( | const char * | file, |
u32 | id | ||
) |
Load a palette from the filesystem to RAM to be used for a sprite.
You must enter the filename without extension. You must use ".pal" extension in all your palette files.
You can store up to 64 palettes, as specified in:
Example:
file | File name without extension. |
id | Slot number (0 - 63). |
void NF_ResetSpriteBuffers | ( | void | ) |
Reset state used for 256 color sprites loaded from FAT.
This function empties all buffers in use and resets variables to their default values. It’s useful to do this when you change a level in a game, to clean all stuff from RAM and make free space to load the new level.
Example:
void NF_SpriteEditPalColor | ( | int | screen, |
u32 | pal, | ||
u32 | number, | ||
u32 | r, | ||
u32 | g, | ||
u32 | b | ||
) |
Changes the value of one color in a sprite palettes of the specified screen.
The change is made in the RAM copy of the palette, so you won't see any change until you update it on VRAM with NF_SpriteUpdatePalette().
Use this function to make cool effect on your sprites.
Example:
screen | Screen (0 - 1). |
pal | Palette index (0 - 15). |
number | Color number (0 - 255). |
r | Red component (0 - 31). |
g | Green component (0 - 31). |
b | Blue component (0 - 31). |
void NF_SpriteGetPalColor | ( | int | screen, |
u32 | pal, | ||
u32 | number, | ||
u8 * | r, | ||
u8 * | g, | ||
u8 * | b | ||
) |
Gets the RGB value of a color of a sprites palette in RAM.
Example:
screen | Screen (0 - 1). |
pal | Palette index (0 - 15). |
number | Color number (0 - 255). |
r | Red component (0 - 31). |
g | Green component (0 - 31). |
b | Blue component (0 - 31). |
void NF_SpriteOamSet | ( | int | screen | ) |
Copy data from the shadow OAM used by NFLib to the real OAM of libnds.
OAM must be updated only during the vertical blanking period. For example, if you don't have a vertical blanking interrupt handler, you can do:
If your vertical blanking interrupt handler takes too long to finish, oamUpdate() will be called outside of the vertical blanking period, which will cause issues. In that case, call the functions from the interrupt handler.
screen | Screen (0 - 1). |
void NF_SpriteSetPalColor | ( | int | screen, |
u32 | pal, | ||
u32 | number, | ||
u32 | r, | ||
u32 | g, | ||
u32 | b | ||
) |
Changes a color of a sprite palette in the specified screen.
The change is made directly in VRAM, so it may be overwritten from the copy in RAM.
Example:
screen | Screen (0 - 1). |
pal | Palette index (0 - 15). |
number | Color number (0 - 255). |
r | Red component (0 - 31). |
g | Green component (0 - 31). |
b | Blue component (0 - 31). |
void NF_SpriteUpdatePalette | ( | int | screen, |
u32 | pal | ||
) |
Updates a sprite palette in VRAM with the copy in RAM of it.
Example:
screen | Screen (0 - 1). |
pal | Palette index (0 - 15). |
void NF_UnloadSpriteGfx | ( | u32 | id | ) |
Delete from RAM the graphics of the selected slot and mark it as free.
You can delete the graphics from RAM once the sprite is created if you don't need it anymore or, if it's animated, after transferring all frames to VRAM.
Example:
id | Slot number (0 - 255). |
void NF_UnloadSpritePal | ( | u32 | id | ) |
Delete the selected palette from RAM and mark it as free.
You can delete it if you don't need it anymore or if it's already in VRAM.
id | Slot number (0 - 63). |
void NF_VramSpriteGfx | ( | int | screen, |
u32 | ram, | ||
u32 | vram, | ||
bool | keepframes | ||
) |
Copy a graphics object from RAM to VRAM of the selected screen to be used as a sprite.
You must specify if you want to copy all frames to VRAM (false) or just the first one (true).
Example:
screen | Screen (0 - 1). |
ram | RAM slot (0 - 255). |
vram | VRAM slot (0 - 127). |
keepframes | For animated sprites. If true, copy all frames to VRAM. |
void NF_VramSpriteGfxDefrag | ( | int | screen | ) |
Defragments the free VRAM used for sprite graphics.
This function is automaticaly executed when fragmented free VRAM is bigger than 50% of the total free VRAM. You don’t need to manually execute this function. You can get the state of VRAM reading the following variables:
Example:
screen | Screen (0 - 1). |
void NF_VramSpritePal | ( | int | screen, |
u32 | id, | ||
u32 | slot | ||
) |
Copy the palette from RAM to a slot of extended palettes in VRAM.
If the slot is in use, its contents are overwritten.
Example:
screen | Screen (0 - 1). |
id | VRAM slot (0 - 64). |
slot | VRAM slot (0 - 15). |