刚接触不久就遇到困难------自定义loading。想和其他获取图片方式一样获取加载界面的图片,结果发现资源还没加载就需要图片,在网上百度了许多,都没有找到正确的方式,通过自己的摸索,终于,,,我成功了。。。

下面介绍一下主要思想:

首先,我们需要使用异步加载的方式,在加载界面之前加载loading界面需要的素材,然后再loadingUI中就可以大胆使用它了。

其次,我们经常碰到的问题是自定义进度条不显示问题。那是因为你没有在Main中把它加载舞台上。

最后,看看具体实现方法吧。

1.新建load界面需要的资源组loading

2.添加load界面需要的图片,并加入配置表相应位置

3.main中添加代码:

private loadingView: LoadingUI;

    private async runGame() {
await this.loadResource();
await this.loadConfig();
this.stage.removeChild(this.loadingView);
this.initGame();
// const result = await RES.getResAsync("description_json")
// this.startAnimation(result);
await platform.login();
const userInfo = await platform.getUserInfo();
console.log(userInfo); }
private async loadResource() {
try {
await RES.loadConfig("resource/default.res.json", "resource/");
await RES.loadGroup("loading")
const loadingView = new LoadingUI();
this.stage.addChild(loadingView);
RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
await this.loadTheme();
await RES.loadGroup("preload", , loadingView);
this.stage.removeChild(loadingView);
}
catch (e) {
console.error(e);
}
}
private loadTheme() {
return new Promise((resolve, reject) => {
// load skin theme configuration file, you can manually modify the file. And replace the default skin.
//加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
let theme = new eui.Theme("resource/default.thm.json", this.stage);
theme.addEventListener(eui.UIEvent.COMPLETE, () => {
//设置加载进度界面
this.loadingView = new LoadingUI();
this.stage.addChild(this.loadingView);
resolve();
}, this); })
}
private onResourceProgress(event: RES.ResourceEvent): void {
if (event.groupName == "preload") {
this.loadingView.onProgress(event.itemsLoaded, event.itemsTotal);
}
}

4.在LoadingUI中修改代码为:

class LoadingUI extends egret.Sprite implements RES.PromiseTaskReporter {

    public constructor() {
super();
if (!this.pBar) {
this.createView();
}
}
private pBar: eui.ProgressBar;
private bg:egret.Bitmap; private async createView(){ this.bg=new egret.Bitmap();
this.bg.texture=RES.getRes("开始界面_png");
// this.bg.width=this.stage.stageWidth;
// this.bg.height=this.stage.stageHeight;
this.addChild(this.bg); this.pBar = new eui.ProgressBar();
this.pBar.x = ;
this.pBar.y = ;
this.pBar.width = ;
this.pBar.height = ;
this.pBar.maximum = ;
this.pBar.minimum = ;
this.pBar.value = ;
this.addChild(this.pBar);
}
private createBitmapByName(name: string): egret.Bitmap {
var result: egret.Bitmap = new egret.Bitmap();
var texture: egret.Texture = RES.getRes(name);
result.texture = texture;
return result;
}
public onProgress(current: number, total: number): void {
if (this.pBar.labelDisplay != null || this.pBar.labelDisplay != undefined) {
// egret.log("加载进度条~~~~~");
this.pBar.labelDisplay.textColor = 0xff0000;
this.pBar.value = current;
} }
}

至此,自定义加载界面完成,当然,你还可以根据自己喜爱添加,修改加载界面布局

Egret白鹭开发小游戏之自定义load加载界面的更多相关文章

  1. 从零到一:用Phaser.js写意地开发小游戏(Chapter 3 - 加载游戏资源)

    回顾 上一节我们搭建了游戏的骨架,添加了四个游戏场景,分别是加载.开始.游戏.结束.那么这一节我们来介绍加载这个场景,顺带丰富一下各个场景的基本内容. Phaser.Loader Phaser框架自带 ...

  2. Egret白鹭开发小游戏中容易犯的错

    在游戏开发过程中遇到问题,请首先查阅:http://developer.egret.com/cn/github/egret-docs/Engine2D/minigame/minigameFAQ/ind ...

  3. 我的Android进阶之旅------>Android疯狂连连看游戏的实现之加载界面图片和实现游戏Activity(四)

    正如在<我的Android进阶之旅------>Android疯狂连连看游戏的实现之状态数据模型(三)>一文中看到的,在AbstractBoard的代码中,当程序需要创建N个Piec ...

  4. Egret白鹭H5小游戏开发入门(二)

    前言: 昨天的文章中简单的介绍了Egret白鹭引擎从安装到基本的使用配置等问题,今天着重介绍H5小游戏开发的起步阶段,如Wing面板的使用,素材的处理,类的说明,开始布局等等. 整体概况: 根据上一篇 ...

  5. Egret白鹭H5小游戏开发入门(三)

    前言: 在上一篇文章中着重介绍了H5小游戏开发的起步阶段,如Wing面板的使用,素材的处理,类的说明等等,那么今天主要是涉及到场景的创建,loading的修改等等的代码编写. 对于这一节,我在讲解的过 ...

  6. Egret白鹭H5小游戏开发入门(一)

    前言: 好久没更新博客了,以前很多都不会,所以常常写博客总结,倒是现在有点点经验了就懒了.在过去的几个月里,在canvas游戏框架方面,撸过了CreateJS,玩得了Egret,又学过PIXI.js. ...

  7. 使用cocos2d-x v3.1开发小游戏(基本框架)

    小游戏的组成 欢迎界面 在游戏资源未全部加载完之前就需要载入,避免进入游戏会有一段黑屏时间. 可以用来展示游戏名称或者开发者logo. 开始菜单界面 一般用于显示游戏名称和关卡选择(或者称游戏难度选择 ...

  8. Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条

    Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条 异步任务相信大家应该不会陌生,那么本章内容MOMO将带领大家学习Unity中的一些异步任务.在同步加载游戏场景的时候通常会使用方法 Ap ...

  9. 一步一步开发Game服务器(三)加载脚本和服务器热更新(二)完整版

    上一篇文章我介绍了如果动态加载dll文件来更新程序 一步一步开发Game服务器(三)加载脚本和服务器热更新 可是在使用过程中,也许有很多会发现,动态加载dll其实不方便,应为需要预先编译代码为dll文 ...

随机推荐

  1. nginx目录穿越漏洞复现

    nginx目录穿越漏洞复现 一.漏洞描述 Nginx在配置别名(Alias)的时候,如果忘记加/,将造成一个目录穿越漏洞. 二.漏洞原理 1. 修改nginx.conf,在如下图位置添加如下配置 在如 ...

  2. 利用DOMNodeInserted监听标签内容变化

    var exeFlag = 0;//控制执行业务次数标记$('#list1').bind('DOMNodeInserted', function () { if(!/img/.test($(" ...

  3. Salesforce Admin篇(三) Delegated Administrator

    项目中,我们可能会遇见以下的场景. 1. HR 经理针对申请者和工作相关的表的app会经常需要修改布局查看需要的页面的字段: 2. 开发者将record type对应的picklist values等 ...

  4. Linux AUFS 文件系统

    AUFS 的英文全称为 Advanced Mult-Layered Unification Filesystem,曾经是 Another Mult-Layered Unification Filesy ...

  5. python课堂整理6---字典

    一.字典  dict info = {"k1" : "v1", "k2" : "v2"} 以键值对形式组成字典 字典里的 ...

  6. 【Demo 1】基于object_detection API的行人检测 1:环境与依赖

    环境 系统环境: win10.python3.6.tensorflow1.14.0.OpenCV3.8 IDE: Pycharm 2019.1.3.JupyterNotebook 依赖 安装objec ...

  7. Linux基础之特殊权限

    22.5)特殊权限 22.5.1)SetUID(简称suid)(数字权限是4000) 命令功能: 临时使用命令的属主权限执行该命令.即如果文件有suid权限时,那么普通用户去执行该文件时,会以该文件的 ...

  8. tornado并发性能测试

    1.带server2.0装饰器 接口访问数据库查询 并发100 平均每秒处理11.8次请求 平均响应时间6944ms 接口不做任何处理 并发100 平均每秒处理99.9次请求 平均响应时间3ms 并发 ...

  9. cookbook_数据结构和算法

    1.1将数据分解为单独的变量 list_a = [1,2,3,4,5,6,7,8,9] a,b,c,d,e,f,g,h,i = list_a print(a,b,c,d,e,f,g,h,i) #使用相 ...

  10. 安装使用xen虚拟化工具

    换了一家新公司,需要拿出一套虚拟化方案,就把业界的主流虚拟化技术划拉了一遍,给领导交了一份报告,具体的技术部分已经在之前的随笔里了,本篇文章主要介绍的是xen虚拟化工具的安装: Xen官方部署文档:h ...