mirror of
https://github.com/knightfox75/nds_nflib.git
synced 2025-06-18 08:45:35 -04:00
examples: Add example of using affine sprites
This commit is contained in:
parent
0159fb67bf
commit
cc40a1daad
1
examples/graphics/spriteaffine/Makefile
Normal file
1
examples/graphics/spriteaffine/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include ../../Makefile.example
|
BIN
examples/graphics/spriteaffine/assets/ball.png
Normal file
BIN
examples/graphics/spriteaffine/assets/ball.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
8
examples/graphics/spriteaffine/assets/convert.sh
Normal file
8
examples/graphics/spriteaffine/assets/convert.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
BLOCKSDS="${BLOCKSDS:-/opt/blocksds/core/}"
|
||||||
|
GRIT=$BLOCKSDS/tools/grit/grit
|
||||||
|
|
||||||
|
$GRIT ball.png -ftB -fh! -gTFF00FF -gt -gB8 -m!
|
||||||
|
|
||||||
|
mv *.pal *.img ../nitrofiles/sprite
|
BIN
examples/graphics/spriteaffine/nitrofiles/sprite/ball.img
Normal file
BIN
examples/graphics/spriteaffine/nitrofiles/sprite/ball.img
Normal file
Binary file not shown.
BIN
examples/graphics/spriteaffine/nitrofiles/sprite/ball.pal
Normal file
BIN
examples/graphics/spriteaffine/nitrofiles/sprite/ball.pal
Normal file
Binary file not shown.
109
examples/graphics/spriteaffine/source/main.c
Normal file
109
examples/graphics/spriteaffine/source/main.c
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
//
|
||||||
|
// SPDX-FileContributor: NightFox & Co., 2009-2011
|
||||||
|
// SPDX-FileContributor: Antonio Niño Díaz, 2025
|
||||||
|
//
|
||||||
|
// Affine sprite loading example
|
||||||
|
// http://www.nightfoxandco.com
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <nds.h>
|
||||||
|
#include <filesystem.h>
|
||||||
|
|
||||||
|
#include <nf_lib.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Set random seed based on the current time
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
// Prepare a NitroFS initialization screen
|
||||||
|
NF_Set2D(0, 0);
|
||||||
|
NF_Set2D(1, 0);
|
||||||
|
consoleDemoInit();
|
||||||
|
printf("\n NitroFS init. Please wait.\n\n");
|
||||||
|
printf(" Iniciando NitroFS,\n por favor, espere.\n\n");
|
||||||
|
swiWaitForVBlank();
|
||||||
|
|
||||||
|
// Initialize NitroFS and set it as the root folder of the filesystem
|
||||||
|
nitroFSInit(NULL);
|
||||||
|
NF_SetRootFolder("NITROFS");
|
||||||
|
|
||||||
|
// Initialize 2D engine in both screens and use mode 0
|
||||||
|
NF_Set2D(0, 0);
|
||||||
|
NF_Set2D(1, 0);
|
||||||
|
|
||||||
|
// Initialize sprite system
|
||||||
|
NF_InitSpriteBuffers(); // Initialize storage buffers
|
||||||
|
NF_InitSpriteSys(0); // Top screen
|
||||||
|
NF_InitSpriteSys(1); // Bottom screen
|
||||||
|
|
||||||
|
NF_LoadSpriteGfx("sprite/ball", 0, 32, 32);
|
||||||
|
NF_LoadSpritePal("sprite/ball", 0);
|
||||||
|
|
||||||
|
// Transfer the required sprites to VRAM
|
||||||
|
NF_VramSpriteGfx(1, 0, 0, true);
|
||||||
|
NF_VramSpritePal(1, 0, 0);
|
||||||
|
|
||||||
|
// Setup ball sprites
|
||||||
|
NF_CreateSprite(1, 10, 0, 0, 16, 16);
|
||||||
|
NF_EnableSpriteRotScale(1, 10, 4, false); // rotation ID 4, no double size
|
||||||
|
|
||||||
|
NF_CreateSprite(1, 20, 0, 0, 128, 16);
|
||||||
|
NF_EnableSpriteRotScale(1, 20, 4, true); // rotation ID 4, double size
|
||||||
|
|
||||||
|
NF_CreateSprite(1, 30, 0, 0, 16, 96);
|
||||||
|
NF_EnableSpriteRotScale(1, 30, 5, false); // rotation ID 5, no double size
|
||||||
|
|
||||||
|
NF_CreateSprite(1, 40, 0, 0, 128, 96);
|
||||||
|
NF_EnableSpriteRotScale(1, 40, 5, true); // rotation ID 5, double size
|
||||||
|
|
||||||
|
int angle = 512;
|
||||||
|
int scale = 350;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
scanKeys(); // Read keypad
|
||||||
|
u16 keys = keysHeld(); // Keys currently pressed
|
||||||
|
|
||||||
|
// Rotate and scale sprites
|
||||||
|
|
||||||
|
if (keys & KEY_LEFT)
|
||||||
|
angle += 16;
|
||||||
|
if (keys & KEY_RIGHT)
|
||||||
|
angle -= 16;
|
||||||
|
|
||||||
|
angle &= 511;
|
||||||
|
|
||||||
|
if (keys & KEY_A)
|
||||||
|
{
|
||||||
|
scale += 2;
|
||||||
|
if (scale > 512)
|
||||||
|
scale = 512;
|
||||||
|
}
|
||||||
|
if (keys & KEY_B)
|
||||||
|
{
|
||||||
|
scale -= 2;
|
||||||
|
if (scale < 0)
|
||||||
|
scale = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
NF_SpriteRotScale(1, 4, angle, scale, scale);
|
||||||
|
NF_SpriteRotScale(1, 5, -angle, scale, scale);
|
||||||
|
|
||||||
|
// Update OAM array
|
||||||
|
NF_SpriteOamSet(0);
|
||||||
|
NF_SpriteOamSet(1);
|
||||||
|
|
||||||
|
// Wait for the screen refresh
|
||||||
|
swiWaitForVBlank();
|
||||||
|
|
||||||
|
// Update OAM
|
||||||
|
oamUpdate(&oamMain);
|
||||||
|
oamUpdate(&oamSub);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user