METHODS of the class
Method
NGN_TextureData* Texture(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(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_SpriteData* Sprite(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(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(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(
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(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(
std::string filepath, // File to load
uint32_t frame = 0 // Frame to convert (default is the first frame)
);
Description
Loads sprite data and returns the pixels of the specified frame (default is the first frame) in RAW format. Returns NULL in case of error.
Example
NGN_RawImage* pixels = ngn->load->SpriteAsRaw("data/coin.spr", 3);
Method
bool SpriteAsRawVector(
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 (all frames by default) 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(std::string filepath);
// Second Overload
std::string TextFile(
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 buffer 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;
buffer.clear();
ngn->load->TextFile("data/script.txt", buffer);
Method
int32_t LoadFile(
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. 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
void SetDisk();
Description
From that moment on, set the device's file system as the data source for loading methods.
Example
ngn->load->SetDisk();
Method
bool SetPackage(std::string pkg_file, std::string key = "");
Description
From that moment on, set a file package created with the NGN_FileSystem tool as the data source for loading methods. If the files in the package are encrypted, the encryption key must be provided as the second parameter.
Example
ngn->load->SetPackage("gamedata.pkg", "myawesomekey");