NightFox’s Lib
Data Structures | Functions | Variables
Affine background support.

Functions to load and manage affine tiled backgrounds. More...

Data Structures

struct  NF_TYPE_AFFINE_BG
 Struct that holds information about affine tiled backgrounds. More...
 

Functions

void NF_InitAffineBgSys (int screen)
 Initializes the affine background system of the selected screen. More...
 
void NF_LoadAffineBg (const char *file, const char *name, u32 width, u32 height)
 Load an affine background to RAM from the filesystem. More...
 
void NF_CreateAffineBg (int screen, u32 layer, const char *name, u32 wrap)
 Create an affine background in a layer using graphics preloaded in RAM. More...
 
void NF_DeleteAffineBg (int screen, u32 layer)
 Deletes from VRAM the background of the specified screen and layer. More...
 
void NF_AffineBgTransform (int screen, u32 layer, s32 x_scale, s32 y_scale, s32 x_tilt, s32 y_tilt)
 Modify the transformation matrix of the specified background. More...
 
void NF_AffineBgMove (int screen, u32 layer, s32 x, s32 y, s32 angle)
 Moves the affine background to the specified position. More...
 

Variables

NF_TYPE_AFFINE_BG NF_AFFINE_BG [2][4]
 Information of all affine backgrounds.
 

Detailed Description

Functions to load and manage affine tiled backgrounds.

Affine backgrounds can be rotated and scaled, unlike regular tiled backgrounds.

Function Documentation

◆ NF_AffineBgMove()

void NF_AffineBgMove ( int  screen,
u32  layer,
s32  x,
s32  y,
s32  angle 
)

Moves the affine background to the specified position.

You can also specify the rotation of this background (between -2048 and 2048). Affine backgrounds can't be moved with NF_ScrollBg().

Example:

// Move the background of the top screen in layer 3 to coordinates (128, 96)
// and rotate it by 45 degrees clockwise.
NF_AffineBgMove(0, 3, 128, 96, 256);
void NF_AffineBgMove(int screen, u32 layer, s32 x, s32 y, s32 angle)
Moves the affine background to the specified position.
Definition: nf_affinebg.c:484
Parameters
screenScreen (0 - 1).
layerLayer (2 - 3).
xX coordinate.
yY coordinate.
angleRotation angle (-2048 to 2048).

◆ NF_AffineBgTransform()

void NF_AffineBgTransform ( int  screen,
u32  layer,
s32  x_scale,
s32  y_scale,
s32  x_tilt,
s32  y_tilt 
)

Modify the transformation matrix of the specified background.

You can change the scale of the X and Y axes, as well as their shear.

Example:

// Zoom the bottom screen background in layer 3 to the 50% of its size.
NF_AffineBgTransform(0, 3, 512, 512, 0, 0);
void NF_AffineBgTransform(int screen, u32 layer, s32 x_scale, s32 y_scale, s32 x_tilt, s32 y_tilt)
Modify the transformation matrix of the specified background.
Definition: nf_affinebg.c:437
Parameters
screenScreen (0 - 1).
layerLayer (2 - 3).
x_scaleScale X: 0 - 256 (original) - 512 (or more)
y_scaleScale Y: 0 - 256 (original) - 512 (or more)
x_tiltTilt X: 0 - 512 (or more)
y_tiltTilt Y: 0 - 512 (or more)

◆ NF_CreateAffineBg()

void NF_CreateAffineBg ( int  screen,
u32  layer,
const char *  name,
u32  wrap 
)

Create an affine background in a layer using graphics preloaded in RAM.

Specify if you want the background infinite (wrap = 1) or not (wrap = 0).

Example:

// Create a background on screen 0, layer 3, using the background graphics
// "waves", with wrapping enabled.
NF_CreateAffineBg (0, 3, "waves", 1);
void NF_CreateAffineBg(int screen, u32 layer, const char *name, u32 wrap)
Create an affine background in a layer using graphics preloaded in RAM.
Definition: nf_affinebg.c:159
Parameters
screenScreen (0 - 1).
layerLayer (2 - 3).
nameName of the background.
wrapTrue to enable wrap around mode.

◆ NF_DeleteAffineBg()

void NF_DeleteAffineBg ( int  screen,
u32  layer 
)

Deletes from VRAM the background of the specified screen and layer.

Example:

// Delete the background of the top screen in layer 3
void NF_DeleteAffineBg(int screen, u32 layer)
Deletes from VRAM the background of the specified screen and layer.
Definition: nf_affinebg.c:375
Parameters
screenScreen (0 - 1).
layerLayer (2 - 3).

◆ NF_InitAffineBgSys()

void NF_InitAffineBgSys ( int  screen)

Initializes the affine background system of the selected screen.

Once this function is called, only affine backgrounds can be used, and only layers 2 and 3 are available. Also, affine backgrounds can only hold up to 256 tiles each, and they must share a 256 color palette.

The 2D hardware needs to be set to video mode 2.

Example:

// Initialize affine mode in the top screen
void NF_InitAffineBgSys(int screen)
Initializes the affine background system of the selected screen.
Definition: nf_affinebg.c:22
Parameters
screenScreen (0 - 1).

◆ NF_LoadAffineBg()

void NF_LoadAffineBg ( const char *  file,
const char *  name,
u32  width,
u32  height 
)

Load an affine background to RAM from the filesystem.

It is essential to initialize the tiled background buffers before loading any "affine" background. See the documentation of NF_InitTiledBgBuffers().

Affine backgrounds have to be 256x256 or 512x512 pixels in size and they can have up to 256 unique tiles. All backgrounds in the same screen must share the palette. Use the script "Convert_Affine.bat" in the GRIT folder to convert your backgrounds.

Example:

// Load the "waves512" background from the backgrounds folder, name it
// "waves" and specify that the background is 512 x 512 pixels.
NF_LoadAffineBg("bg/waves512", "waves", 512, 512);
void NF_LoadAffineBg(const char *file, const char *name, u32 width, u32 height)
Load an affine background to RAM from the filesystem.
Definition: nf_affinebg.c:88
Parameters
fileFile path without extension.
nameName used for the BG for other functions.
widthBG width.
heightBG height.