Hello,
In Phaser (the 2D engine), there is a clear separation between the time at which you load your assets and the time at which you use your asset in the game.
Basically, you first load your assets in an asset manager, giving names to your assets, and then you access your assets during the game using the names you gave them:
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.image('einstein', 'assets/pics/ra_einstein.png');
}
function create() {
var s = game.add.sprite(80, 0, 'einstein');
s.rotation = 0.14;
}
Because I found this approach to be clean and simple. I am looking at a way to do it in BabylonJS.
It seems to me that I can load all of my assets easily with the AssetManager
(Load Files with Assets Manager - Babylon.js Documentation). This object has a callback onFinish
so that you can start the game (or game level) after all the assets are loaded.
My main problem is that, once I loaded the assets this way, how do I do to access them?
I thought that an easy way do to it was to use the scene as an asset “accessor” and access the assets this way:
let sound = scene.getSoundByName('violon18.vaw');
mySound.play();
However, I realised that the following functions do not exist:
let text = scene.getTextFileByName("text_name");
let binary = scene.getBinaryFileByName("binary_name");
let image = scene.getImageByName("image_name");
let texture = scene.getTextureByName("image_name");
Does that sound crazy to access the assets as if they were in a “library”? I think that would be very helpful on my side
PS: In fact, I thought the asset container would be exactly that kind of library (Use an AssetContainer - Babylon.js Documentation) but no, it isn’t.