METHODS of the class
Method
NGN_TextureData* Texture(const std::string& filepath);
Description
Loads a PNG image and converts it to texture data. The maximum supported image size is 8192x8192 pixels. Returns NULL in case of an error.
Example
NGN_TextureData* bg_grid = ngn->load->Texture("data/png/grid.png");
Method
NGN_TiledBgData* TiledBg(const std::string& filepath);
Description
Loads tileset data from a .tbg file (Refer to the accompanying utilities of the library). The maximum size of the tileset is 8192x8192 pixels. Returns NULL in case of an error.
Example
NGN_TiledBgData* tiles_bg_front = ngn->load->TiledBg("data/bg/bg_front.tbg");
Method
NGN_IndexedTiledBgData* IndexedTiledBg(
const std::string& bg_file, // Tiles + map file (.itb)
const std::string& pal_file, // Color palette file (.pal)
const std::string& cyc_file = "" // (Optional) Palette cycling animation file (.cyc)
);
Description
Loads indexed tiled background data from an .itb file along with its color palette file (.pal) and an optional .cyc palette animation cycle file (Refer to the accompanying utilities of the library). Returns NULL in case of an error.
Example
NGN_IndexedTiledBgData* idx_bg = ngn->load->IndexedTiledBg("data/bg/stage1.itb", "data/bg/stage1.pal", "data/bg/stage1.cyc");
Method
NGN_SpriteData* Sprite(const std::string& filepath);
Description
Loads sprite data from a .spr file (Refer to the accompanying utilities of the library). The maximum size of each frame of the sprite is 8192x8192 pixels. Returns NULL in case of an error.
Example
NGN_SpriteData* wizard_sprite = ngn->load->Sprite("data/spr/wizard.spr");
Method
NGN_CollisionMapData* CollisionMap(const std::string& filepath);
Description
Loads collision map data from a .map file (Refer to the accompanying utilities of the library). Returns NULL in case of an error.
Example
NGN_CollisionMapData* collision_map = ngn->load->CollisionMap("data/collision/mainmap.map");
Method
NGN_AudioClipData* AudioClip(const std::string& filepath);
Description
Loads an audio file in WAV, FLAC, or OGG format and converts it to AudioClipData for use as a sound effect. Returns NULL in case of an error.
Example
NGN_AudioClipData* coin_sfx = ngn->load->AudioClip("data/wav/coin.wav");
Method
NGN_TextFont* TrueTypeFont(
const std::string& filepath, // File to load
uint32_t height, // Font height (in pixels)
bool antialias = true, // Antialias?
uint32_t font_color = 0xFFFFFF, // Base color (RGB)
uint32_t outline = 0, // Outline? (in pixels)
uint32_t outline_color = 0x000000 // Outline color (RGB)
);
Description
Loads a TRUE TYPE font file and generates textures for each character with the specified font size and properties. Returns NULL if unable to load or convert the font.
Example
NGN_TextFont* font = ngn->load->TrueTypeFont("data/consolas.ttf", 24);
Method
NGN_RawImage* PngAsRaw(const std::string& filepath);
Description
Loads an image in PNG format and returns its pixels in RAW format. Returns NULL in case of error.
Example
NGN_RawImage* pixels = ngn->load->PngAsRaw("data/clouds.png");
Method
NGN_RawImage* SpriteAsRaw(
const std::string& filepath, // File to load
uint32_t frame = 0 // Frame to convert (0 by default)
);
Description
Loads sprite data and returns the pixels of the specified frame in RAW format. Returns NULL in case of error.
Example
NGN_RawImage* pixels = ngn->load->SpriteAsRaw("data/coin.spr", 3);
Method
bool SpriteAsRawVector(
const std::string& filepath, // File to load
std::vector<NGN_RawImage*>& raw_frames, // Destination vector for frames
uint32_t first_frame = 0, // Initial frame (0 by default)
uint32_t last_frame = NGN_DEFAULT_VALUE // Final frame (last frame by default)
);
Description
Loads sprite data and stores the pixels of the specified frames in RAW format within a vector. Returns true on success and false in case of error.
Example
std::vector<NGN_RawImage*> frames;
ngn->load->SpriteAsRawVector("data/coin.spr", frames, 2, 5);
Method
// First Overload
std::string TextFile(const std::string& filepath);
// Second Overload
bool TextFile(
const std::string& filepath, // Filepath
std::vector<std::string>& text_lines // Destination buffer
);
Description
Reads the text file from the specified path and returns it as a string (first overload), or stores the text lines from the file into the given vector and returns true or false based on success (second overload).
Example
// First Overload
std::string text = ngn->load->TextFile("data/script.txt");
// Second Overload
std::vector<std::string> buffer;
ngn->load->TextFile("data/script.txt", buffer);
Method
int32_t LoadFile(
const std::string& filepath, // Filepath
std::vector<uint8_t>& data // Data vector
);
Description
Reads the file from the specified path in the device's file system or from a file package (see SetDisk() and SetPackage()), and places the data into the given vector. If the file is read from a package and it is encrypted, the content will be decrypted automatically. The method returns the number of bytes read or -1 in case of an error.
Example
std::vector<uint8_t> buffer;
int32_t file_length = ngn->load->LoadFile("data/stage.bin", buffer);
Method
int32_t LoadFileChunk(
const std::string& filepath, // Path to the file
std::vector<uint8_t>& data, // Storage vector
uint32_t offset, // Starting byte for reading
uint32_t length // Number of bytes to read
);
Description
Loads a specific chunk of a file from the default source (either the file system or a data package). If the file is encrypted, the method will automatically decrypt it during loading. It returns the number of bytes read or -1 if an error occurs.
Example
std::vector<uint8_t> chunk;
int32_t bytes_read = ngn->load->LoadFileChunk("data/assets.pkg", chunk, 1024, 512);
Method
void SetDisk();
Description
Sets the device's file system as the default data source for all loading methods.
Example
ngn->load->SetDisk();
Method
bool SetPackage(
const std::string& pkg_file, // Package file
std::string key = "" // Encryption key (optional)
);
Description
Sets a file package created with the NGN_FileSystem tool as the default data source for loading methods. If the files in the package are encrypted, the encryption key must be provided as the second parameter. Returns true if the package was set successfully, false otherwise.
Example
ngn->load->SetPackage("gamedata.pkg", "myawesomekey");
Method
bool PackageEnabled();
Description
Returns a boolean value indicating whether a data package file is currently being used as the data source (true) or direct disk access (false).
Example
if (ngn->load->PackageEnabled()) {
// Source: data package
}