module
Eagle::Assets
Overview
Loads and caches game files: images, textures, sounds, fonts, shaders and meshes.
Each loader caches by path, so asking for the same file twice returns the same object
and costs nothing. The load methods on Texture, Sound, Font, Shader and Mesh
all go through here.
Paths can be absolute, relative to the assets folder, or prefixed with res://. The
assets folder is found in this order:
- the
EAGLE_ASSETSenvironment variable Config#assets_dir- an
assets/folder next to the executable - an
assets/folder in the working directory - the working directory itself
Files embedded with Eagle.embed_assets take priority over the disk.
tex = Assets.texture("res://sprites/hero.png")
level = Assets.read("res://levels/1.txt")
Assets.invalidate("res://levels/1.txt") # re-read on the next load, for hot reload
Defined in:
eagle/assets/assets.crClass Method Summary
-
.add_search_path(path : String) : Nil
Adds another folder to search when a file isn't in the assets folder, such as a mod folder.
-
.clear : Nil
Forgets every cached asset and frees GPU objects.
-
.embedded?(p : String) : Bool
True when p was embedded with
Eagle.embed_assets. -
.embedded_paths : Array(String)
Every embedded path.
-
.exists?(p : String) : Bool
True when the asset exists, embedded or on disk.
-
.font(p : String, size : Number) : Font
Loads and caches a TrueType
Fontat a pixel size. -
.image(p : String) : Image
Loads and caches an
Image. -
.invalidate(p : String) : Nil
Forgets one cached entry, so the next load reads the file again.
-
.mesh(p : String) : Mesh
Loads and caches a
Meshfrom an OBJ file. -
.path(p : String) : String
The file path p resolves to, without checking that it exists.
-
.read(p : String) : String
Reads a text file.
-
.read_bytes(p : String) : Bytes
Reads a binary file.
-
.root : String
The assets folder that relative and
res://paths resolve against. -
.root=(path : String | Nil)
Sets the assets folder.
-
.shader(p : String) : Shader
Loads and caches a
Shader. -
.sound(p : String) : Sound
Loads and caches a
Sound(WAV or Ogg Vorbis). -
.texture(p : String, filter : GPU::Filter = Texture.default_filter, wrap : GPU::Wrap = GPU::Wrap::Clamp, mipmaps : Bool = false) : Texture
Loads and caches a
Texture.
Class Method Detail
Adds another folder to search when a file isn't in the assets folder, such as a mod folder.
Forgets every cached asset and frees GPU objects. Use it between levels that share nothing, or before reloading everything.
Forgets one cached entry, so the next load reads the file again.
Reads a binary file. Raises AssetError when it doesn't exist.
Loads and caches a Texture. The cache key includes the path only, so the first load decides the filter.