assets folder. nf build copies its content next to the game code, so assets/hero.png becomes /hero.png.
Read an asset
The asset library is built into every application: you never register it. Read a file withctx.assets.getAsset(path) wherever you have the context. Load each file once, not on every tick: a scene’s load is a good place, and it can wait for the file (see Scenes).
getAsset returns an NfFile:
- Paths are normalized:
"hero.png","/hero.png"and"//hero.png"find the same file. getAssetthrowsNfNotFoundwhen no file has that path. The read methods fetch the file and throwNfFetchExceptionwhen the fetch fails.
In main
main has no context. There, read the URL from the run options: options.files.get("/hero.png") returns the same URL as getAsset("/hero.png").path, or undefined when the file is missing. Sound and music shows an example.
To change the folder name, set dir.assets in the app’s nanoforge.config.ts. See the configuration file.