LifecycleContext 示例
protected createChildren(): void {
super.createChildren();
console.log('egret.lifecycle.contexts.length', egret.lifecycle.contexts.length); // 1, 系統預設有一個 LifecycleContext
egret.lifecycle.addLifecycleListener((context: egret.lifecycle.LifecycleContext) => {
// custom lifecycle plugin
window.onblur = () => context.pause(); // 滑鼠點擊示窗外
window.onfocus = () => context.resume(); // 滑鼠點擊示窗內
})
console.log('egret.lifecycle.contexts.length', egret.lifecycle.contexts.length); // 2, addLifecycleListener 會新增一個 LifecycleContext 用以設置客製化內容
// 設置心跳開關
egret.lifecycle.onPause = () => egret.ticker.pause();
egret.lifecycle.onResume = () => egret.ticker.resume();
// 動畫, 受 egret.ticker 影響
let s = new egret.Shape();
s.graphics.beginFill(0xFF0000);
s.graphics.drawRect(0, 0, 100, 100);
s.graphics.endFill();
this.addChild(s);
egret.Tween.get(s, { loop: true }).set({ x: 0 }).to({ x: 200 }, 1000);
}
沒有留言:
張貼留言