Appearance
Class: GroupLoader
资源组加载
ts
// 创建资源组加载器
const loader = new GroupLoader();
// 设置最大可同时加载4个
loader.workerCount = 4;
// 监听单个资源加载完成事件
loader.emitter.on(GroupLoader.Event.LOADED, ({ count, loaded }) => {
console.log('资源加载中:', loaded, '/', count);
}, this);
// 监听所有资源加载完成事件
loader.emitter.on(GroupLoader.Event.COMPLATE, () => {
console.log('资源加载完成');
}, this);
// 设置待加载资源列表
const list: LoadResListConfig = [
// 只设置路径
'./assets/photo.png',
// 设置路径加别名
['./assets/bmg.mp3', 'bgm_mp3']
];
// 加入待加载列表
loader.add(list);
// 开始加载资源
loader.start();
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new GroupLoader()
Defined in
src/core/resource/GroupLoader.ts:40
Properties
count
• count: number
= 0
资源总数
Defined in
src/core/resource/GroupLoader.ts:59
emitter
• emitter: EventEmitter
<ValueOf
<{ COMPLATE
: "complate"
= 'complate'; LOADED
: "loaded"
= 'loaded' }>, any
>
Defined in
src/core/resource/GroupLoader.ts:50
index
• index: number
= 0
当前处理的位置
Defined in
src/core/resource/GroupLoader.ts:67
list
• list: LoadResListConfig
= []
Defined in
src/core/resource/GroupLoader.ts:39
loaded
• loaded: number
= 0
已经加载数量
Defined in
src/core/resource/GroupLoader.ts:63
workerCount
• workerCount: number
= 1
同时加载最大数量
Defined in
src/core/resource/GroupLoader.ts:55
Event
▪ Static
Event: Object
Type declaration
Name | Type |
---|---|
COMPLATE | "complate" |
LOADED | "loaded" |
Defined in
src/core/resource/GroupLoader.ts:43
Methods
add
▸ add(list
): void
添加需要加载的资源
ts
const list: LoadResListConfig = [
// 只设置路径
'./assets/photo.png',
// 设置路径加别名
['./assets/bmg.mp3', 'bgm_mp3']
];
Parameters
Name | Type | Description |
---|---|---|
list | LoadResListConfig | 资源列表 |
Returns
void
Defined in
src/core/resource/GroupLoader.ts:119
load
▸ load(): void
顺序加载资源
Returns
void
Defined in
src/core/resource/GroupLoader.ts:73
start
▸ start(): void
启动加载
Returns
void