"COCOS2D-JS Official Documents" Ii. Resource Manager Assets Manager

Source: Internet
Author: User
Tags getmessage

This document describes a new heavyweight feature of COCOS2D-JS 3.0: Resource Manager (JSB only). The resource Manager is designed for hot updates to the resources of the game runtime, where resources can be pictures, audio, and even game scripts themselves. Using Explorer, you will be able to upload new resources to your server, your game will track changes on the remote server, download new resources to the user's device and use the new resources in the game. In this way, new designs, new gameplay experiences, and even new game content will be instantly pushed to your users ' hands. The important thing is that you don't need to repackage your app for every channel and go through a painful app update review, and there's no cost to this process!

Usage Scenarios

Imagine your game has been published in the store, but you suddenly find a design omission or some very negative user feedback, you must be worried, but after the completion of the modification, you still have to wait for countless channels of software packaging and annoying App Store audit ... Until you go through the audit, you also need to update your software version, or ... The audit may not be a pass. See here, people with such experience will not be a good mood, I would like to say that this process is too painful, and many users may have been lost in the process.

Other usage scenarios:

    • Valentine's Day is coming, you want to organize an in-game activity, missing the timing is definitely the last thing you want to see.
    • When you find a serious bug.
    • When you want to add some new scenes or levels to prolong the life of the game.
    • And very many other situations ...

In these cases, if you can quickly deploy to the user after the development is completed, I say fast, maybe one night, isn't that fascinating? The Explorer is designed for these situations.

Characteristics

Cocos2d-js v3.0 RC0 version of the resource manager has added a lot of powerful features, making the process of hot update faster and more convenient.

    • Multi-threaded Parallel download support
    • Two-tier Progress statistics: file-level and byte-level
    • Zip compressed file support
    • Breakpoint Continuation
    • Detailed Error Reporting
    • File download failed retry support
Use of the resource Manager

In fact, using the resource manager is fairly straightforward, first of all, you will need a JSON-formatted initial configuration file (manifest) in your app package.

In this configuration file, you need to provide the corresponding profile address on the server, the current resource version and a set of resource descriptions, and then you can use the API in the game code jsb.AssetsManager to check or update the latest version of the corresponding resource.

Configuration file

Here is a simple example of a configuration file:

  {"PackageURL": "http://example.com/assets_manager/TestScene/", "Remoteversionurl": "http://example.com /assets_manager/testscene/version.manifest "," Remotemanifesturl ":" http://example.com/assets_manager/TestScene/ Project.manifest "," Version ":" 1.0.0 "," engineversion ":" Cocos2d-js v3.0 RC0 "," assets ": {" Images/back        Ground.jpg ": {" MD5 ":" ... "}," Images/icon.png ": {" MD5 ":" ... "},        "Images/button.png": {"MD5": "..."}, "Src/game.js": {"MD5": "..."},            "Src/layer.js": {"MD5": "..."}, "Compressed.zip": {"MD5": "...", "Compressed": true}, "Searchpaths": ["res/"]}  
    • PackageURL: The download root path of the remote resource.
    • Remoteversionurl: The path to the remote version file to determine if there is a new version of the resource on the server side.
    • Remotemanifesturl: The path to the remote configuration file that contains the version information and all resource information.
    • Version: The revision of the configuration file.
    • Engineversion: The engine version that corresponds to the configuration file.
    • Assets: all resource information.
      • Key: Keys represent relative paths to resources (relative to PackageURL).
      • The MD5:MD5 value represents the version information for the resource file.
      • Compressed: [optional] If the value is true, the file is automatically unzipped after it is downloaded, currently only supported in ZIP compression format.
    • Searchpaths: A list of search paths that need to be added to the cocos2d engine.

The version file version.manifest file should contain the first five information that is identical to the configuration file. This file is optional, and if it is not found or fails successfully, the resource Manager will automatically download the full configuration file. However, when the configuration file contains a lot of resources, the version file will greatly shorten the time of the version comparison.

Use JSB. Assetsmanager

The following is jsb.AssetsManager the sample code used:

var manager = new JSB. Assetsmanager (Manifesturl, Storagepath); Manager.update ();//Because the download process is asynchronous, You need to increase the number of indexes on the manager to ensure that it is not freed by Cocos2d-x memory Management Manager.retain (), if (!manager.getlocalmanifest (). isLoaded ()) {Cc.log (" Fail to update assets, step skipped. "); else {var listener = new CC. Eventlistenerassetsmanager (Manager, function (event) {switch (Event.geteventcode ()) {case CC.                EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:cc.log ("NO LOCAL MANIFEST file found, skip assets update.");            Break Case CC.                EventAssetsManager.UPDATE_PROGRESSION:var percent = event.getpercent ();                var filepercent = Event.getpercentbyfile (); Cc.log ("Download percent:" + percent + "|                File percent: "+ filepercent);            Break Case CC. EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:case cc. EventAssetsManager.ERROR_PARSE_MANIFEST:cc.log ("Fail to download MANIFEST file, uPdate skipped. ");            Break Case CC. EventAssetsManager.ALREADY_UP_TO_DATE:case cc.                EventAssetsManager.UPDATE_FINISHED:cc.log ("UPDATE finished.");                Since the manager's reference count is increased, you need to release it at the appropriate time and make sure that the object is no longer used to manager.release ();            Break Case CC.                EventAssetsManager.UPDATE_FAILED:cc.log ("UPDATE FAILED." + event.getmessage ());                directly re-download the failed resources, it is recommended that you count the number of retries, more than a certain number of abandoned manager.downloadfailedassets ();            Break Case CC. EventAssetsManager.ERROR_UPDATING:cc.log ("Asset update ERROR:" + event.getassetid () + "," + event.getmes                Sage ());            Break Case CC.                EventAssetsManager.ERROR_DECOMPRESS:cc.log (Event.getmessage ());            Break        Default:break; }    }}

You can also refer to js-tests the Extensions/AssetsManagerTest test examples in. jsb.AssetsManagerthe other APIs are as follows:

    • Checkupdate ()
    • GetState ()
    • Getstoragepath ()
    • Getlocalmanifest ()
    • Getremotemanifest ()
Known bugs

The resource manager may encounter problems with the Windows and iOS emulator that cannot be created and downloaded, and we will resolve this issue as soon as possible, while debugging using the iOS real-time machine.

"COCOS2D-JS Official Documents" Ii. Resource Manager Assets Manager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.