25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
import LoadingCatAnimation from '../Script/LoadingCatAnimation';
|
|
|
|
/** Clone the scene's shared loading view so another feature's animation is never stopped. */
|
|
export default class RankingLoading {
|
|
static show(context: cc.Node): () => void {
|
|
let host = context;
|
|
while (host && !host.getChildByName('Loading')) host = host.parent;
|
|
const template = host && host.getChildByName('Loading');
|
|
if (!template) return () => {};
|
|
const size = host.getContentSize(), scale = Math.min(1, size.width / 1080, size.height / 1920);
|
|
if (scale <= 0) return () => {};
|
|
const viewport = new cc.Node('RankingCatLoading');
|
|
viewport.setContentSize(size.width / scale, size.height / scale); viewport.scale = scale;
|
|
host.addChild(viewport); viewport.zIndex = cc.macro.MAX_ZINDEX;
|
|
viewport.addComponent(cc.BlockInputEvents);
|
|
const loading = cc.instantiate(template); viewport.addChild(loading);
|
|
LoadingCatAnimation.play(loading);
|
|
let stopped = false;
|
|
return () => {
|
|
if (stopped) return; stopped = true;
|
|
if (cc.isValid(viewport, true)) { LoadingCatAnimation.stop(loading); viewport.destroy(); }
|
|
};
|
|
}
|
|
}
|