-
Notifications
You must be signed in to change notification settings - Fork 0
Working with AssetManager
bapquad edited this page Feb 28, 2022
·
2 revisions
This content show you how to work with
AssetManager
in CaremJS. How your game load assets into it's cycle.
The AssetManager
provide the container holds your application's assets. You can include types of asset such that images, sounds and fonts.
For working with images in AssetManager
you need to declare types of images. By example, you can understand how to use Asset Manager with images.
import {Carem} from '@bapquad/carem'
// Create new a assetManager
let assetManager = new Carem.AssetManager("gif|png|jpg");
// Queue images
assetManager.QueueFile("img001.jpg");
assetManager.QueueFile("img002.jpg");
assetManager.QueueFile("img003.jpg");
// Download images
assetManager.QueueDownloadAll();
For working with sounds in asset manager you need to declare types of sounds.
import {Carem} from '@bapquad/carem'
// Create new a assetManager
let assetManager = new Carem.AssetManager("", "mp3|ogg|wav");
// Queue sounds
assetManager.QueueFile("snd001.wav");
assetManager.QueueFile("snd002.wav");
assetManager.QueueFile("snd003.wav");
// Download sounds
assetManager.QueueDownloadAll();
The below example show you how to use AssetManager
with fonts
import {Carem} from '@bapquad/carem'
// Create new a assetManager
let assetManager = new Carem.AssetManager("", "", "woff2");
// Queue fonts
assetManager.QueueFile("fnt001.woff2");
assetManager.QueueFile("fnt002.woff2");
assetManager.QueueFile("fnt003.woff2");
// Download fonts
assetManager.QueueDownloadAll();
Now your assets are being downloaded. You can't use these assets right now. You need to wait it completely loaded. You would use these asset like as below example.
function gaming()
{
console.log(assetManager.GetAsset("img001.jpg"));
}
function loading()
{
if(assetManager.IsComplete())
{
UnTick(tickID);
return gaming();
}
else
{
return Tick(loading);
}
}
let tickID = loading();