新增sceneTransition 用于场景过渡
This commit is contained in:
41
source/src/Utils/ContentManager.ts
Normal file
41
source/src/Utils/ContentManager.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
class ContentManager {
|
||||
protected loadedAssets: Map<string, any> = new Map<string, any>();
|
||||
|
||||
/** 异步加载资源 */
|
||||
public load(name: string, local: boolean = true): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let res = this.loadedAssets.get(name);
|
||||
if (res) {
|
||||
resolve(res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (local) {
|
||||
RES.getResAsync(name).then((data) => {
|
||||
this.loadedAssets.set(name, data);
|
||||
resolve(data);
|
||||
}).catch((err) => {
|
||||
console.error("资源加载错误:", name, err);
|
||||
reject(err);
|
||||
});
|
||||
} else {
|
||||
RES.getResByUrl(name).then((data) => {
|
||||
this.loadedAssets.set(name, data);
|
||||
resolve(data);
|
||||
}).catch((err) => {
|
||||
console.error("资源加载错误:", name, err);
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public dispose(){
|
||||
this.loadedAssets.forEach(value => {
|
||||
let assetsToRemove = value;
|
||||
assetsToRemove.dispose();
|
||||
});
|
||||
|
||||
this.loadedAssets.clear();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ class TouchState {
|
||||
public get position(){
|
||||
return new Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
|
||||
public reset(){
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
@@ -26,6 +26,8 @@ class Input {
|
||||
private static _totalTouchCount: number = 0;
|
||||
/** 返回第一个触摸点的坐标 */
|
||||
public static get touchPosition(){
|
||||
if (!this._gameTouchs[0])
|
||||
return Vector2.zero;
|
||||
return this._gameTouchs[0].position;
|
||||
}
|
||||
/** 获取最大触摸数 */
|
||||
@@ -65,12 +67,12 @@ class Input {
|
||||
return delta;
|
||||
}
|
||||
|
||||
public static initialize(){
|
||||
public static initialize(stage: egret.Stage){
|
||||
if (this._init)
|
||||
return;
|
||||
|
||||
this._init = true;
|
||||
this._stage = SceneManager.getActiveScene().stage;
|
||||
this._stage = stage;
|
||||
this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
|
||||
this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this);
|
||||
this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
|
||||
|
||||
Reference in New Issue
Block a user