Egret飞行模拟-开发记录03-LoadingUI界面
class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {
public constructor() {
super();
// 当被添加到舞台的时候触发 (被添加到舞台,说明资源组已经加载完成)
this.addEventListener(egret.Event.ADDED_TO_STAGE,this.createView,this);
}
private loadlable: egret.BitmapText;
private loadImg: egret.Bitmap // loading图标
private shape:egret.Shape = new egret.Shape();
private createView(): void {
this.width=this.stage.stageWidth;
this.height=this.stage.stageHeight;
//背景色
let bg:egret.Shape = this.shape;
bg.graphics.beginFill(0x40BDC9);
bg.graphics.drawRect(0, 0, this.width, this.height);
bg.graphics.endFill();
this.addChild(this.shape);
// 加载位图字体
this.loadlable = new egret.BitmapText();
this.loadlable.font = RES.getRes("gameFonts_fnt");;
this.loadlable.textAlign = "center";
this.loadlable.verticalAlign = "middle";
this.loadlable.width = 140;
this.loadlable.height = 80;
this.loadlable.x = this.width / 2 - this.loadlable.width / 2;
this.loadlable.y = this.height / 2 + this.loadlable.height / 2;
this.addChild(this.loadlable);
// loading图标
this.loadImg = new egret.Bitmap();
this.loadImg.texture=RES.getRes("loader_png");
this.loadImg.anchorOffsetX = this.loadImg.width / 2;
this.loadImg.anchorOffsetY = this.loadImg.height / 2;
this.loadImg.x = this.width / 2;
this.loadImg.y = this.height / 2;
this.addChild(this.loadImg);
}
public onProgress(current: number, total: number): void {
// 计算百分比
let per = Math.floor((current / total) * 100);
this.loadlable.text = `${per}%`;
}
}
2、main.ts里的代码没有变,但是loadResource方法里的加载顺序要搞清楚。核心关键点。
private async runGame() {
RES.setMaxLoadingThread(1); //防加载卡死
await this.loadResource();
this.createGameScene();
}
private async loadResource() {
try {
await RES.loadConfig("resource/default.res.json", "resource/");
const loadingView = new LoadingUI();
//加载loading组
await RES.loadGroup("loading");
this.stage.addChild(loadingView);
await this.loadTheme();
await RES.loadGroup("preload", 0, loadingView);
this.stage.removeChild(loadingView);
}
catch (e) {
console.error(e);
}
}
class LoadingUI extends eui.Component {
public lblLoader: eui.BitmapLabel;
public constructor() {
super();
this.skinName = "resource/skins/LoadingSkin.exml";
}
public setProgress(current: number, total: number):void {
// 计算百分比
let per = Math.floor((current / total) * 100);
this.lblLoader.text = `${per}%`;
}
}
2、main.ts源码:
class Main extends eui.UILayer {
private loadingView: LoadingUI;
protected createChildren(): void {
super.createChildren();
egret.lifecycle.addLifecycleListener((context) => {
// custom lifecycle plugin
})
egret.lifecycle.onPause = () => {
egret.ticker.pause();
}
egret.lifecycle.onResume = () => {
egret.ticker.resume();
}
//inject the custom material parser
//注入自定义的素材解析器
let assetAdapter = new AssetAdapter();
egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
//初始化Resource资源加载库
RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
RES.loadConfig("resource/default.res.json", "resource/");
/*this.runGame().catch(e => {
console.log(e);
})*/
}
/**
* 配置文件加载完成,开始预加载皮肤主题资源和preload资源组。
* Loading of configuration file is complete, start to pre-load the theme configuration file and the preload resource group
*/
private onConfigComplete(event:RES.ResourceEvent):void {
RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
// load skin theme configuration file, you can manually modify the file. And replace the default skin.
//加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
var theme = new eui.Theme("resource/default.thm.json", this.stage);
theme.addEventListener(eui.UIEvent.COMPLETE, this.onThemeLoadComplete, this);
RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onResourceLoadComplete, this);
RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onResourceLoadError, this);
RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, this.onItemLoadError, this);
RES.loadGroup("loading");
}
private isThemeLoadEnd: boolean = false;
/**
* 主题文件加载完成,开始预加载
*/
private onThemeLoadComplete(): void {
this.isThemeLoadEnd = true;
this.createScene();
}
private isResourceLoadEnd: boolean = false;
/**
* 资源组加载完成
*/
private onResourceLoadComplete(event:RES.ResourceEvent):void {
if (event.groupName == "loading") {
RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onResourceLoadComplete, this);
RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onResourceLoadError, this);
RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, this.onItemLoadError, this);
this.isResourceLoadEnd = true;
this.createScene();
}
if(event.groupName == 'preload'){
this.startCreateScene();
this.stage.removeChild(this.loadingView);
}
}
private createScene(){
if(this.isThemeLoadEnd && this.isResourceLoadEnd){
//设置加载进度界面
this.loadingView = new LoadingUI();
this.stage.addChild(this.loadingView);
// 加载preload资源组
RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE,this.onResourceLoadComplete,this);
RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR,this.onResourceLoadError,this);
RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS,this.onResourceProgress,this);
RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR,this.onItemLoadError,this);
RES.loadGroup("preload");
}
}
/**
* 资源组加载出错
* The resource group loading failed
*/
private onItemLoadError(event:RES.ResourceEvent):void {
console.warn("Url:" + event.resItem.url + " has failed to load");
}
/**
* 资源组加载出错
*/
private onResourceLoadError(event:RES.ResourceEvent):void {
//TODO
console.warn("Group:" + event.groupName + " has failed to load");
//忽略加载失败的项目
this.onResourceLoadComplete(event);
}
/**
* preload资源组加载进度
*/
private onResourceProgress(event:RES.ResourceEvent):void {
if (event.groupName == "preload") {
this.loadingView.setProgress(event.itemsLoaded, event.itemsTotal);
}
}
/**
* 创建场景界面
*/
protected startCreateScene(): void {
console.log('start')
this.playsc1();
}
public sc1: eui.Component;
protected playsc1():void{
var sc1: eui.Component = new GameLogo();
this.stage.addChild(sc1);
this.sc1 = sc1;
}
}
3、default.thm.json
{
"skins": {
"eui.Button": "resource/eui_skins/ButtonSkin.exml",
"eui.CheckBox": "resource/eui_skins/CheckBoxSkin.exml",
"eui.HScrollBar": "resource/eui_skins/HScrollBarSkin.exml",
"eui.HSlider": "resource/eui_skins/HSliderSkin.exml",
"eui.Panel": "resource/eui_skins/PanelSkin.exml",
"eui.TextInput": "resource/eui_skins/TextInputSkin.exml",
"eui.ProgressBar": "resource/eui_skins/ProgressBarSkin.exml",
"eui.RadioButton": "resource/eui_skins/RadioButtonSkin.exml",
"eui.Scroller": "resource/eui_skins/ScrollerSkin.exml",
"eui.ToggleSwitch": "resource/eui_skins/ToggleSwitchSkin.exml",
"eui.VScrollBar": "resource/eui_skins/VScrollBarSkin.exml",
"eui.VSlider": "resource/eui_skins/VSliderSkin.exml",
"eui.ItemRenderer": "resource/eui_skins/ItemRendererSkin.exml",
"LoadingUI": "resource/skins/LoadingSkin.exml",
"GameLogo": "resource/skins/GameLogo.exml"
},
"autoGenerateExmlsList": true,
"exmls": [
"resource/eui_skins/ButtonSkin.exml",
"resource/eui_skins/CheckBoxSkin.exml",
"resource/eui_skins/HScrollBarSkin.exml",
"resource/eui_skins/HSliderSkin.exml",
"resource/eui_skins/ItemRendererSkin.exml",
"resource/eui_skins/PanelSkin.exml",
"resource/eui_skins/ProgressBarSkin.exml",
"resource/eui_skins/RadioButtonSkin.exml",
"resource/eui_skins/ScrollerSkin.exml",
"resource/eui_skins/TextInputSkin.exml",
"resource/eui_skins/ToggleSwitchSkin.exml",
"resource/eui_skins/VScrollBarSkin.exml",
"resource/eui_skins/VSliderSkin.exml",
"resource/skins/GameLogo.exml",
"resource/skins/LoadingSkin.exml"
],
"path": "resource/default.thm.json"
}
Egret飞行模拟-开发记录03-LoadingUI界面的更多相关文章
- Egret飞行模拟-开发记录02
1.Egret异步加载资源制作loading界面 使用EUI,EXML组件制作loading界面时,需要皮肤主题资源加载控制.即default.thm.json配置文件. 下一篇专门记录这部分. 2. ...
- Egret飞行模拟-开发记录01
1.项目结构简介 1.1 index.html:应用入口文件,我们可以在这里面配置项目的旋转缩放模式背景颜色等. 1.2 egretProperties.json:这个文件里面进行项目配置,包括模块和 ...
- 微信小程序-饮食日志_开发记录03
这段时间主要是收尾阶段. 美化界面,排版分部等. 并进行上传,审核. 环境部署一直出现问题,所以测试版食物查找查找不到. 主要问题是:https://的网页证书没有通过审核. 所以现在推行开发,调试版 ...
- CozyRSS开发记录22-界面退化
CozyRSS开发记录22-界面退化 1.问题1-HtmlTextBlock 找的这个HtmlTextBlock有很严重的bug,有时候显示不完全,有时候直接就崩了.然后看了下代码,完全是学生仔水平写 ...
- CozyRSS开发记录16-RssContentView显示
CozyRSS开发记录16-RssContentView显示 1.RssContentView的布局和绑定 继续参照原型图来写xaml: 然后在RSSContentFrameViewModel里提供绑 ...
- CozyRSS开发记录15-获取和显示RSS内容
CozyRSS开发记录15-获取和显示RSS内容 1.内容列表 我们先给RSSContentFrame增加一个ViewModel,里面和RSS源列表一样,提供一个ObservableCollectio ...
- CozyRSS开发记录14-RSS源管理初步完工
CozyRSS开发记录14-RSS源管理初步完工 1.添加源的响应 DialogHost.Show有几个版本的重载,加一个DialogClosingEventHandler参数.我们让添加源对话框的添 ...
- CozyRSS开发记录13-添加订阅的对话框
CozyRSS开发记录13-添加订阅的对话框 1.设计对话框 首先,还是先用MockPlus来画个原型图: 因为用了MaterialDesignToolkit,那么可以很方便的有一个蒙层的效果. 2. ...
- CozyRSS开发记录2-酷炫的皮肤库
CozyRSS开发记录2-酷炫的皮肤库 1.MaterialDesignToolkit 最开始微软推出Metro设计风格的时候,有人喜欢有人喷.紧接着,Ios也开始做扁平化的UI,这时候,扁平化已成为 ...
随机推荐
- python 发送163邮件
可能还需要使用 邮箱第三方客户端的授权码. 网易163免费邮箱相关服务器信息 from email import encoders from email.header import Header fr ...
- char[]的toString() 和 String.valueOf(char[])的区别
之前看到其他博客里说,toString 和 String.valueOf()功能相同,但是我发现对于char[]来说并不是这样的: 示例1: 先比较一下: public static void mai ...
- git版本管理工具常用命令
git是分布式版本管理工具,一台电脑既可以是客户端,也可以是服务端.工作过程中可以断开网络.svn是集中式版本管理工具,一台服务器控制很多客户端,使用过程不能断网. git的优点有:适合分布式开发,强 ...
- [删括号][判断可行性的dp]
链接:https://ac.nowcoder.com/acm/problem/21303来源:牛客网题目描述 给你一个合法的括号序列s1,每次你可以删除一个"()" 你可以删除0个 ...
- OO第二单元作业分析
前言 这一单元关于线程安全的作业结束了,在助教提供的接口的帮助以及老师提供的设计模型的指导下,这三次作业还是相对轻松地完成了,中间也没有出现什么bug,可能就是因为简单的逻辑不容易出错吧,可惜两次都由 ...
- git 创建删除分支
进入仓库目录 -- 查看本地分支 git branch -- 查看远程分支 git branch -r -- 查看远程和本地的分支 git branch -a -- 下载远程分支代码,并切换到分支 进 ...
- 《python for data analysis》第九章,数据聚合与分组运算
# -*- coding:utf-8 -*-# <python for data analysis>第九章# 数据聚合与分组运算import pandas as pdimport nump ...
- sosreport-汇总收集linux系统信息
有时候我们想将Linux服务器信息一次性查询并导出发送给他人,我们可以使用这个sosreport这个工具 安装 yum install sos -y 收集信息 sosreport 收集到的信息默认保 ...
- Mysql ssl 连接
在Azure创建了一个Mysql5.7服务,因为默认使用ssl连接,需要下载Azure的证书,并使用openssl生成客户端的证书.具体流程参考官方文档 大致步骤: 下载根证书, 安装openssl, ...
- S50 抓取pattern数据
S50(原V50) 测试机台湾久元电子研发的一款数字芯片测试系统,行业内有很多人使用: 现在记录下S50抓取pattern数据的一些方法: 程序主要是通过read_log配合c代码实现,pattern ...