How do you go to all your sprites in your project?
I need this for a loading screen for my new game
I need this for a loading screen for my new game
sprites are preloaded during the loading sequence microstudio already adds so you don't have to make a loading screen for that but if you want a loading screen for fonts and stuff
Loading assets Unlike sprites, maps and other built-in assets, the custom assets you import are not preloaded when you run your microStudio project. You need to load them from your code. Loading is asynchronous and you have two ways to check if your asset is loaded and ready to be used:
You can set an optional callback function ; the function will be called when the asset is loaded, with the data passed as argument. The loading function also returns a loader object, which has a property .ready. Once you can check that the property is set to 1 (true), the data is ready and attached as a property of the loader object. asset_manager.loadFont( "myfolder/myfont" ) Initiates the loading of a font asset.
You can then check if the font is ready and use the font just like built-in fonts:
if screen.isFontReady("myfont") then ... end
screen.setFont("myfont")
loader = asset_manager.loadJSON( "myfolder/myjsonfile", callback )
Initiates the loading of a JSON file asset. The result will be a microScript object holding all the data.
Loading is asynchronous, you have two ways to check when loading is complete:
Example using a callback function
asset_manager.loadJSON("somefolder/myjsonfile", function(data)
myobject = data
end)
Example using the loader object
loader = asset_manager.loadJSON("somefolder/myjsonfile")
(...)
if loader.ready then myobject = loader.data end loader = asset_manager.loadText( "myfolder/myjsonfile", callback )
Initiates the loading of a text file asset. The result will be a microScript string holding all the text.
Loading is asynchronous, you have two ways to check when loading is complete:
Example using a callback function
asset_manager.loadText("somefolder/mytextfile", function(text) mytext = text end) Example using the loader object loader = asset_manager.loadText("somefolder/mytextfile")
(...)
if loader.ready then mytext = loader.text end loader = asset_manager.loadCSV( "myfolder/mycsvfile", callback )
Initiates the loading of a CSV file asset. The result will be a microScript string holding all the text of the file.
Note: CSV file contents are returned as if it was a plain text file. You have to handle all the parsing from your code. Loading is asynchronous, you have two ways to check when loading is complete:
Example using a callback function
asset_manager.loadCSV("somefolder/mycsvfile", function(text) mytext = text end) Example using the loader object loader = asset_manager.loadCSV("somefolder/mycsvfile")
(...)
if loader.ready then mytext = loader.text end loader = asset_manager.loadMarkdown( "myfolder/mymdfile", callback )
Initiates the loading of a .md file asset. The result will be a microScript string holding all the text of the file.
Example using a callback function
asset_manager.loadMarkdown("somefolder/mymdfile", function(text) mytext = text end)
Example using the loader object
loader = asset_manager.loadMarkdown("somefolder/mymdfile")
(...)
if loader.ready then mytext = loader.text end loader = asset_manager.loadModel( "myfolder/mymodelfile", callback )
Initiates the loading of a 3D model. This only works if you have picked Babylon.js or micro3D as graphics engines for your project. The result is a container object holding all the model data.
Loading is asynchronous, you have two ways to check when loading is complete:
Example using a callback function
asset_manager.loadModel("somefolder/mymodelfile", function(container) container.addAllToScene() // or check Babylon.js documentation for other ways to handle the result // asset_manager.loadModel is mapped on BABYLON.SceneLoader.LoadAssetContainer end) Example using the loader object loader = asset_manager.loadModel("somefolder/mymodelfile")
(...)
if loader.ready then loader.container.addAllToScene() end loader = asset_manager.wasmInstance( "folder/wasm_module", callback )
Creates a new instance of the given WebAssembly module. The result is a WebAssembly.Instance object that can be used directly from microScript or JavaScript.
Loading is asynchronous, you have two ways to check when loading is complete:
Example using a callback function
asset_manager.wasmInstance("somefolder/wasm_module", function(instance) local add = instance.exports.add print( add( 2, 3 ) ) end) Example using the loader object loader = asset_manager.wasmInstance("somefolder/wasm_module")
(...)
if loader.ready then local add = loader.instance.exports.add print( add( 4, 5 ) ) end ```