Asset Management

There are two ways to load assets: 1. Preloaded by Reference; 2 Dynamic Loading

Preloaded by Reference

The assets are loaded before the game logical code is executed. Normally the references are specified in scene editing and prefab editing

  • Reference Texture Asset
    Set the UIImage object's texture property or define the qc.Serializer.TEXTURE type's field in behaviour script

  • Reference Animation Asset
    Set the Sprite object's texture property or define the qc.Serializer.TEXTURE type's field in behaviour script

  • Reference Sound Asset
    Set the Sound object's audio property or define the qc.Serializer.AUDIO type's field in behaviour script

  • Reference Font Asset Set the UIText object's font property or define the qc.Serializer.FONT type's field in behaviour script

  • Reference Prefab Asset
    Define the qc.Serializer.PREFAB type's field in behaviour script

  • Reference Excel Asset
    Define the qc.Serializer.EXCELASSET type's field in behaviour script

  • Reference Text Asset
    Define the qc.Serializer.TEXTASSET type's field in behaviour script

Dynamic Loading

For some assets, you don't want them to be preloaded, then you can download them at runtime programmly. See game.assets.load

  • Load texture asset:'Assets/texture/texture.bin', function(r) {
      // Find the UIImage object to set texture asset'UIRoot/background').texture = r;
  • Load audio asset'Assets/audio/newlevel.mp3.bin', function(r) {
      // Find the Sound object to set audio asset
      var soundCtrl ='Sound');
      if (! {
 = r;
  • Load animation asset'Assets/sprites/panda.bin', function(r) {
      // Find the Sprite object to set animation asset
      var spriteCtrl ='Sprite');
      spriteCtrl.texture = r;
      spriteCtrl.playAnimation('atk2', 1, false);
  • Load webFont asset'Assets/font/HK.bin', function(r) {
      // Find the UIText object to set font asset
      var textCtrl = self.font.find('UIText');
      textCtrl.fontFamily = qc.UIText.WEBFONT;
      textCtrl.font = r;
  • Load prefab asset'Assets/prefabs/prefab.bin', function(r) {
      // Clone a new game object from prefab asset, and add to the game, self.gameObject.find('list'));
  • Load excel asset'Assets/excel/mother.bin', function(r) {
      // Print all the sheets name from the excel asset
  • Load text asset'Assets/excel/mario_map.bin', function(r) {
      // Print the json content from the text asset

Release Asset

We recommand to use the way "Preloaded by Reference", if you need to load assets dynamiclly, we recommand you to use URL as key, to make the keys easy to maintain:

// Load with one param as key and URL'Assets/sprites/panda.bin');

After assets are loaded, they are saved in memory, there are two ways to unload the loaded assets.

  1. Call game.assets.unload, specify the asset key, url or object to unload.'Assets/sprites/panda.bin');
  2. When switching scene, set the second param as true to clear all the loaded assets'nextState', true);


Assets API


Assets Demo