When the user’s network speed is slow and the game files are loaded, we have a situation where we are currently loading some files and want to open another scene and need to load another file. Egret queues are loaded on a “first request, first load” basis for files of equal priority, meaning that new scenes are loaded only after the files in the previous queue have been loaded first.

This experience is not the best user experience. Users want to enter a new scene, but due to the limitations of the number of HTTP connections and loading speed, they have to wait for a while to enter a new scene, which is inconsistent with our product requirements.

Is there any way? Res.loadgroup () has the Priority attribute to control the Priority, but only for loading groups, other loading methods are not supported.

Further analysis of the source code shows that res.getResbyURL and Res.getResAsync API loads are officially set to the lowest priority by default and cannot be changed! The underlying objects of Image objects created by EUI use these two methods.

How to do? In order to better prompt loading experience at the business level, it is only their own modification of the source code, the introduction of queue cleaning mechanism. A manual call is made to clean up the queue of files waiting to be loaded when there is a file loaded first. This is the fastest way to load into the target file.

Modify the file: Egret\engine\ engine version \build\ assetsManager \ assetsManager.js

Res.queue. ClearWaitList && res.queue. ClearWaitList (); */ ResourceLoader.prototype.clearWaitList = function () { this.failedList.length = 0; var exuteFile = []; var resInfo; var list = this.itemListPriorityDic[Number.NEGATIVE_INFINITY]; if(list){ for(var i=0; i<list.length; i++){ resInfo = list[i]; delete this.promiseHash[resInfo.root + resInfo.name]; delete this.dispatcherDic[resInfo.root + resInfo.name]; exuteFile.push(resInfo.root + resInfo.name); } list.length = 0; } for(var priority in this.itemListPrioritydic){var list = this.itemListPrioritydic [priority]; if(list){ for(var groupname in this.promiseHash){ for(var i=0; i<list.length; i++){ resInfo = list[i]; if(resInfo.groupNames && resInfo.groupNames.indexOf(groupname) ! = -1){ delete this.promiseHash[groupname]; delete this.dispatcherDic[groupname]; exuteFile.push(groupname); break; } } } list.length = 0; } } return exuteFile; };Copy the code