1.游戏开发生命周期

关于游戏开发中的生命周期相关的知识,参考一下:https://www.jianshu.com/p/ebc9e087676e

2.egret 2d引擎中的生命周期

对于egret 2D中的生命周期我们来了解一下:
(1)心跳
egret的 SystemTicker,是引擎的心跳计时器,egret通过SystemTicker来执行每一帧的eventLoop,渲染等操作。
保持游戏框架的运行。
pause():void 是暂停心跳的操作。
resume():void 是恢复心跳
update函数,egret在运行每帧是回调。
(2)计时器
egret.startTick(callBack: (timeStamp: number) => boolean, thisObject: any):void;
egret开启计时器的注册函数。
egret.stopTick(callBack: (timeStamp: number) => boolean, thisObject: any): void;
egret停止计时器函数。
在游戏中经常会出现有些对象随着时间的变化而变化的。一旦有这种需求,那么就需要用到计时器 来记录时间并且在合适的时间
里对物品的属性变化进行操作。
如果有大量的这类型的需求,那么我们应该集中来管理,那么就需要一个计时器回调函数管理器。
心跳管理器

/*** Timer管理器*/
class TimerMgr extends BaseClass {private _handlers: Array<TimerHandler>;private _currTime: number;private _currFrame: number;private currHandler: TimerHandler = null;private nexthandles: Array<TimerHandler>;/*** 构造函数*/public constructor() {super();this._handlers = [];this.nexthandles = null;this._currTime = egret.getTimer();this._currFrame = 0;egret.startTick(this.onEnterFrame, this);}public static ins(): TimerMgr {return super.ins() as TimerMgr;}public getFrameId(): number {return this._currFrame;}public getCurrTime(): number {return this._currTime;}// 从大到小排序public static binFunc(b1: TimerHandler, b2: TimerHandler): number {if (b1.exeTime > b2.exeTime) return -1;else if (b1.exeTime < b2.exeTime) return 1;else return 0;}private static DeleteHandle(handler: TimerHandler) {handler.clear();ObjPool.push(handler);}/*** 每帧执行函数* @param frameTime*/private onEnterFrame(time: number): boolean {this._currFrame++;this._currTime = egret.getTimer();let currTime: number = 0;// process the nextlist firstlet nexthandles = this.nexthandles;this.nexthandles = null;if (nexthandles && nexthandles.length > 0) {for (let handler of nexthandles) {handler.method.call(handler.methodObj);TimerMgr.DeleteHandle(handler);}nexthandles = null;}if (this._handlers.length <= 0) return false;let handler = this._handlers[this._handlers.length - 1];while (handler.exeTime <= this._currTime) {this.currHandler = handler = this._handlers.pop();let times = (this._currTime - handler.exeTime) / handler.delay;if (times > 1) {handler.method.call(handler.methodObj, times);} else {handler.method.call(handler.methodObj);}currTime = egret.getTimer();handler.exeTime = currTime + handler.delay;let repeat: boolean = handler.forever;if (!repeat) {if (handler.repeatCount > 1) {handler.repeatCount--;repeat = true;} else {if (handler.onFinish) {handler.onFinish.apply(handler.finishObj);}}}if (repeat) {let index = Algorithm.binSearch(this._handlers, handler, TimerMgr.binFunc);this._handlers.splice(index, 0, handler);}else {TimerMgr.DeleteHandle(handler);}if (currTime - this._currTime > 5) break;if (this._handlers.length <= 0) break;else handler = this._handlers[this._handlers.length - 1];}this.currHandler = null;return false;}private create(startTime: number, delay: number, repeat: number, method: Function, methodObj: any,onFinish: Function, fobj: any, remove: boolean = false): void {if (delay < 0 || repeat < 0 || method == null) {return;}let handler: TimerHandler = ObjPool.pop("TimerHandler");handler.forever = repeat == 0;handler.repeatCount = repeat;handler.delay = delay;handler.method = method;handler.methodObj = methodObj;handler.onFinish = onFinish;handler.finishObj = fobj;handler.exeTime = startTime + this._currTime;// this._handlers.push(handler);let index = Algorithm.binSearch(this._handlers, handler, TimerMgr.binFunc);this._handlers.splice(index, 0, handler);}/**** 定时执行* @param delay 执行间隔:毫秒* @param repeat 执行次数, 0为无限次* @param method 执行函数* @param methodObj 执行函数所属对象* @param onFinish 完成执行函数* @param fobj 完成执行函数所属对象* @param remove 是否删除已经存在的**/public doTimer(delay: number, repeat: number, method: Function, methodObj: any, onFinish: Function = null, fobj: any = null, remove: boolean = false): void {this.create(delay, delay, repeat, method, methodObj, onFinish, fobj, remove);}/**** 定时执行* @param startTime 延迟多久第一次执行* @param delay 执行间隔:毫秒* @param repeat 执行次数, 0为无限次* @param method 执行函数* @param methodObj 执行函数所属对象* @param onFinish 完成执行函数* @param fobj 完成执行函数所属对象* @param remove 是否删除已经存在的**/public doTimerDelay(startTime: number, delay: number, repeat: number, method: Function, methodObj: any, onFinish: Function = null, fobj: any = null): void {this.create(startTime, delay, repeat, method, methodObj, onFinish, fobj);}/** 下一帧执行,且只执行一次*/public doNext(method: Function, methodObj: any) {let handler: TimerHandler = ObjPool.pop("TimerHandler");handler.method = method;handler.methodObj = methodObj;if (!this.nexthandles)this.nexthandles = [];this.nexthandles.push(handler);}/*** 清理* @param method 要移除的函数* @param methodObj 要移除的函数对应的对象*/public remove(method: Function, methodObj: any): void {let currHandler = this.currHandler;if (currHandler && currHandler.method == method &&currHandler.methodObj == methodObj) {currHandler.forever = false;currHandler.repeatCount = 0;}for (let i = this._handlers.length - 1; i >= 0; i--) {let handler = this._handlers[i];if (handler.method == method && handler.methodObj == methodObj) {this._handlers.splice(i, 1);TimerMgr.DeleteHandle(handler);}}}/*** 清理* @param methodObj 要移除的函数对应的对象*/public removeAll(methodObj: any): void {let currHandler = this.currHandler;if (currHandler && currHandler.methodObj == methodObj) {currHandler.forever = false;currHandler.repeatCount = 0;}for (let i = this._handlers.length - 1; i >= 0; i--) {let handler = this._handlers[i];if (handler.methodObj == methodObj) {this._handlers.splice(i, 1);TimerMgr.DeleteHandle(handler);}}}/*** 检测是否已经存在* @param method* @param methodObj**/public isExists(method: Function, methodObj: any): boolean {for (let handler of this._handlers) {if (handler.method == method && handler.methodObj == methodObj) {return true;}}return false;}
}class TimerHandler {/**执行间隔*/public delay: number = 0;/**是否重复执行*/public forever: boolean = false;/**重复执行次数*/public repeatCount: number = 0;/**执行时间*/public exeTime: number = 0;/**处理函数*/public method: Function;/**处理函数所属对象*/public methodObj: any;/**完成处理函数*/public onFinish: Function;/**完成处理函数所属对象*/public finishObj: any;/**清理*/public clear(): void {this.method = null;this.methodObj = null;this.onFinish = null;this.finishObj = null;this.forever = false;}
}

(3)帧事件
帧事件是egret 每一帧都发出的一个基础事件类型。
帧事件的是生命周期的体现,相当于unity的updata函数。
帧事件的监听,继承自DisplayObject

this.addEventListener(egret.Event.ENTER_FRAME,this.onUpdata,this);

移除

this.removeEventListener(egret.Event.ENTER_FRAME,this.onUpdata,this);

egret引擎生命周期相关相关推荐

  1. 软工导第一节课 计算机软件工程学作一个简短的概述,回顾计算机系统发展简史 软件工程的基本原理和方法有概括的本质的认识,详细讲解生命周期相关知识讲解8种典型的软件过程模型

    文章目录 软件危机 软件的定义 软件危机典型表现 产生软件危机的原因 消除软件危机的方法 软件工程 什么是软件工程 软件工程的本质特征 软件工程的基本原理 软件工程方法学 传统方法学 面向对象方法学 ...

  2. 安卓Activity生命周期相关

    安卓Activity生命周期相关 activity作为安卓四大组件之一,是我们在开发中使用的最频繁的组件之一. 在这里就个人所了解的一些东西,和大家分享一下下.有错误之处,多多指正. 典型生命周期 首 ...

  3. 面试:Service及生命周期相关问题

    Q1:Service的两种启动方式: 1.startService 2.bindService(有回调可以和activity进行通信) 注意:在Android 5.0之后google出于安全的角度禁止 ...

  4. android 如何获取离开屏幕时间,android – SurfaceHolder回调如何与Activity生命周期相关?...

    编辑:如果targetSDK大于10,将应用程序睡眠调用onPause和onStop. Source 我在我的姜饼手机上的一个小相机应用程序中查看了活动和SurfaceView的生命周期.你是完全正确 ...

  5. Vuforia官方文档-03-Vuforia Engine 生命周期

    Vuforia官方文档自学,只为学习交流,肯定会有错误与肤浅之处,仅供参考 Vuforia Engine LifeCycle: Vuforia引擎生命周期官方文档:Vuforia Engine Lif ...

  6. vue生命周期及双向绑定

    这篇文章不是原创,看了其他人的分析贴,记录下自己学到的.本篇主要记录一下vue内部流程,以及双向绑定原理.Vue的可爱之处在于他的双向绑定及Virtual DOM的思想. vue内部流程 如图所示,实 ...

  7. Lifecycle Activity和Fragment生命周期感知组件 LifecycleObserver MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. iOS10 UI教程视图的生命周期

    iOS10 UI教程视图的生命周期 说到视图的生命周期一般都是指视图控制器的视图生命周期.在视图的声明周期中最主要的有8个方法,分别为loadView().viewDidLoad().viewWill ...

  9. Hasor:生命周期

    为什么80%的码农都做不了架构师?>>>    首先引用Wiki的介绍一下Hasor:     "Hasor是一款开源框架.它是为了解决企业模块化开发中复杂性而创建的.Ha ...

  10. 【Android 应用开发】UI绘制流程 ( 生命周期机制 | 布局加载机制 | UI 绘制流程 | 布局测量 | 布局摆放 | 组件绘制 | 瀑布流布局案例 )

    文章目录 一. 博客相关资料 及 下载地址 1. 代码查看方法 ( ① 直接获取代码 | ② JAR 包替换 ) 2. 本博客涉及到的源码查看说明 二. Activity 生命周期回调机制 1. An ...

最新文章

  1. MySQL性能优化步骤
  2. 网路防火墙iptables
  3. tsung压测mysql_高并发测试工具Tsung使用教程
  4. 启动数据库时提示ORA-03113: 通信通道的文件结尾解决方法
  5. boost1.55.0在vs2013上编译序列化库失败的解决方法
  6. EF DbContext.Configuration.ProxyCreationEnabled 什么鬼?
  7. 神经网络入门之CNN(二)
  8. Android性能全面分析与优化方案研究—几乎是史上最全最实用的
  9. qpsk调制matlab实现,QPSK调制与解调系统的MATLAB实现
  10. mysql查询名字重复四次以上的人名_怎么查询数据库中重复字段的名字
  11. ROS做端口映射DDNS的N个做法详细教程
  12. 软件中级设计师备考笔记考前记忆
  13. Cypress 前端测试工具的基本使用和相关命令总结
  14. 医院在线预约挂号系统 jsp+mysql+maven
  15. 编写应用程序,计算两个非零正整数的最大公约数和最小公倍数,要求两个非零正整数从键盘输入。
  16. Linux系统开机显示BusyBox v1.22.1 built-in shell(ash) 解决方法
  17. 星光大道视频播放器精品版
  18. java无法验证发布者_Win10弹出无法验证发布者怎么解决?
  19. FAQ 01:合作型多任务与抢先式多任务有和区别
  20. 算法养成:弱鸡大学生浅谈c++stl

热门文章

  1. 古今安全帽头盔大PK,古人安全意识不比今人差
  2. 【NDN安全】Poseidon: Mitigating Interest Flooding DDoS Attacks in Named Data Networking 学习笔记
  3. Keil MDK5 STM32F401CCU6开发环境配置
  4. POJ3345 Bribing FIPA(树形DP)
  5. 知止而后有定,定而后能静,静而后…
  6. 嵌入式设备引入机器学习:有eIQ就够了!
  7. python图像拉伸_python处理图像
  8. C语言编写飞机大战程序,C语言实现简单飞机大战
  9. 1040 实数的打印
  10. STL(标准模板库)