# core/asset (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/core/asset/

Asset.

## Asset extends Object

Asset.

Example: Load an image asset and check its state

```js
import { ImageAsset } from "./build/vanilla.js";

const imageAsset = new ImageAsset();
await imageAsset.load("examples/assets/spritesheet.png");
console.log(imageAsset.getAssetType(), imageAsset.getAssetPath(), imageAsset.isLoaded());
imageAsset.unload();
console.log(imageAsset.isLoaded(), imageAsset.getAssetPath());
```

- `constructor()` (constructor, since 0.0.8): Constructor.
- `async load(assetPath)` (method, since 0.0.8): Loads the asset asynchronously.
  - `assetPath` string: Asset path. (does nothing if already loaded)
  - returns Promise<void>: A promise resolved once the path is set. (this base function does not read anything or change the loaded state)
- `unload()` (method, since 0.0.8): Unloads the asset.
  - Finishes immediately and returns nothing. (the same whether it was loaded or not, same as the overriding subclasses)
- `setAssetType(assetType)` (method, since 0.0.10): Sets the asset type.
  - `assetType` string: Asset type name. (such as "image", "audio", "json", "text", "font", "blob", set by subclasses in their constructor)
- `getAssetType()` (method, since 0.0.10): Returns the asset type.
  - returns string: Asset type name. ("none" if not set)
- `setAssetPath(assetPath)` (method, since 0.0.9): Sets the load path.
  - `assetPath` string: Load path.
- `getAssetPath()` (method, since 0.0.9): Returns the load path.
  - returns string: Load path. (empty string before loading or after unloading)
- `setLoaded(isLoaded)` (method, since 0.0.9): Sets whether it is loaded.
  - `isLoaded` boolean: True if loaded.
- `isLoaded()` (method, since 0.0.8): Returns whether it is loaded.
  - returns boolean: True if loaded.

## AssetType (enum)

Asset type.

- `none` = `none`: No asset type.
- `image` = `image`: Image asset.
- `audio` = `audio`: Audio asset.
- `json` = `json`: JSON asset.
- `text` = `text`: Text asset.
- `font` = `font`: Font asset.
- `blob` = `blob`: Binary blob asset.
- `bunch` = `bunch`: Bundle asset.
- `visual` = `visual`: Visual asset.
