1.加载资源

2.将显示对象添加到显示列表

/////////////*****************************动态帧频***********************************///

private imgLoadHandler(e: egret.Event): void {

//输入帧频
this._textInput = new egret.TextField;
this._textInput.size = 50;
this._textInput.type = "input";
this._textInput.width = 300;
this._textInput.height = 60;
this._textInput.border = true;
this._textInput.borderColor = 0x000000;
this._textInput.textAlign = egret.HorizontalAlign.CENTER;
this._textInput.text = "输入帧频";
this._textInput.textColor = 0x0f0f0f;
this._textInput.x = this.stage.stageWidth / 2 - this._textInput.width / 2;
this._textInput.y = 200;
this._textInput.touchEnabled = true;
this.addChild(this._textInput);

this.stage.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {

//设置帧频
this.stage.frameRate = Number(this._textInput.text);
}, this);
this._textInput.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
this._textInput.text = "";
this._textInput.textColor = 0x000000;
}, this);
//旋转
this.addEventListener(egret.Event.ENTER_FRAME, (e: egret.Event) => {
this.显示对象.rotation += 3;
}, this);
}

/////////////*****************************延迟调用***********************************///

private _txInfo: egret.TextField;

private isComplete: boolean;

private imgLoadHandler(e: egret.Event): void {
//提示信息
this._txInfo = new egret.TextField;
this._txInfo.size = 24;
this._txInfo.textColor = 0x000000;
this._txInfo.lineSpacing = 10;
this._txInfo.multiline = true;
this._txInfo.text = "延迟调用示例\n点击舞台显示效果\n";
this._txInfo.x = 30;
this._txInfo.y = 30;
this.addChild(this._txInfo);

var self = this;
self.isComplete = true;
var backFun: Function = function () {
self.isComplete = true;
};
//点击舞台调用延迟方法
this.stage.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
if (self.isComplete) {
self.isComplete = false;
this.typeEffect(this._txInfo, "每个字符延迟200毫秒调用,实现打字机效果\n", 150, backFun);
}
}, this);
}
/**
* 文字打印效果
* obj 文本对象
* content 文字
* interval 打字间隔 毫秒
*/
private typeEffect(obj, content: string = "", interval: number = 200, backFun: Function = null): void {
var strArr: Array<any> = content.split("");
var len: number = strArr.length;
for (var i = 0; i < len; i++) {
egret.setTimeout(function () {
obj.appendText(strArr[Number(this)]);
if ((Number(this) >= len - 1) && (backFun != null)) {
backFun();
}
}, i, interval * i);
}
}

/////////////*****************************定时器***********************************///

private timer: egret.Timer;
private pointer = new egret.Shape();

private onAddTostage(e: egret.Event) {
//生成表盘
var circle = new egret.Shape();
circle.graphics.lineStyle(5, 0x000000, 1, true);
circle.graphics.drawCircle(0, 0, 170);
circle.graphics.endFill();
circle.x = this.stage.stageWidth / 2;
circle.y = this.stage.stageHeight / 2;
this.addChild(circle);
//指针
this.pointer = new egret.Shape();
this.pointer.graphics.beginFill(0x000000);
this.pointer.graphics.drawRect(0, 0, 160, 5);
this.pointer.graphics.endFill();
this.pointer.anchorOffsetY = this.pointer.height / 2;
this.pointer.x = this.stage.stageWidth / 2;
this.pointer.y = this.stage.stageHeight / 2;
this.addChild(this.pointer);
/// 提示信息
this._txInfo = new egret.TextField;
this._txInfo.size = 24;
this._txInfo.textColor = 0x000000;
this._txInfo.lineSpacing = 10;
this._txInfo.multiline = true;
this._txInfo.text = "定时器示例\n点击舞台启动或者暂停定时器\n";
this._txInfo.x = 30;
this._txInfo.y = 30;
this.addChild(this._txInfo);
var self = this;
this.timer = new egret.Timer(1000, 0);
this.timer.addEventListener(egret.TimerEvent.TIMER, this.timerFunc, this);
this.timer.start();
//点击舞台调用
this.stage.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {

//定时器正在运行
if (this.timer.running) {
this._txInfo.text += "定时器关闭!\n";
this.timer.stop();
} else {
this._txInfo.text += "定时器开启!\n";
this.timer.start();
}
}, this);
}

//指针按照定时每次旋转6度,60秒旋转一周

private timerFunc(e: egret.Event) {
this.pointer.rotation += 6;
if (this.pointer.rotation > 360) {
this.pointer.rotation -= 360;
}
}

http://developer.egret.com/cn/example/egret2d/index.html#080-run-frame-rate

Egret_时间与运行的更多相关文章

  1. 针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行

    <?php//针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行,http://ken.01h.net/define('PHP_LOCK_FILE', dirname(__FILE__ ...

  2. 如何用Qt写一个同一时间只能运行一个实例的应用程序

    http://blog.sina.com.cn/s/blog_6343941a0100nk2x.html 可以达到的目的: 1.应用只启动一个实例,依赖于QtNetwork模块 2.启动时向另一个实例 ...

  3. APP长时间后台运行

    *  参考:http://www.nivalxer.com/archives/187 首先,我要说明的是在iOS中,一般应用程序在后台挂起之后仅拥有3分钟时间来处理相应的未完成事件,但是3分钟之后就会 ...

  4. Android长时间后台运行Service

         项目需要在后台获取GPS经纬度.当用户对手机有一段时间没有操作后,屏幕(Screen)将从高亮(Bright)变为暗淡(Dim),如果再过段时间没操作, 屏幕(Screen)将又由暗淡(Di ...

  5. C# 给某个方法设定执行超时时间 C#如何控制方法的执行时间,超时则强制退出方法执行 C#函数运行超时则终止执行(任意参数类型及参数个数通用版)

    我自己写的 /// <summary> /// 函数运行超时则终止执行(超时则返回true,否则返回false) /// </summary> /// <typepara ...

  6. uptime - 告知系统运行了多久时间

    SYNOPSIS(总览) uptime uptime [-V] DESCRIPTION(描述) uptime 给出下列信息的一行显示. 当前时间, 系统运行了多久时间, 当前登陆的用户有多少, 以及前 ...

  7. iOS---后台运行机制详解

    一.iOS的“伪后台”程序 首先,先了解一下iOS 中所谓的「后台进程」到底是怎么回事吧? Let me be as clear as I can be: the iOS multitasking b ...

  8. 通过监控线程状态来保证socket服务器的稳定运行

    云平台中使用的socket服务器是我们自己定义一套通信协议,并通过C#实现的一个socket服务. 该服务目前是和web服务一起运行在IIS容器中,通过启动一个永不退出的新线程来监听端口. 在开发的初 ...

  9. SQL Server时间粒度系列----第7节日历数据表详解

    本文目录列表: 1.时间粒度有关描述 2.时间维度有关功能函数3.日历数据表 4.日历数据表数据填充 5.总结语 6.参考清单列表   时间粒度有关描述   将该系列涉及到的时间粒度以及分钟以下的粒度 ...

随机推荐

  1. 【调试基础】Part 1 寄存器

    01 寄存器体系 02 16/32/64位寄存器

  2. Python_Mix*生成器,生成器函数,推导式,生成器表达式

    生成器: 生成器的本质就是迭代器 生成器一般由生成器函数或者生成器表达式来创建,其实就是手写的迭代器 def func(): print('abc') yield 222 #由于函数中有了yield ...

  3. javascript中的add(1)(2)(3)(4)是怎么实现的

    javascript中的add(1)(2)(3)(4)是怎么实现的?实现如下: var fn = function(a){ let sum = a; let tempFn = function(b){ ...

  4. 安装selenium,驱动geckodriver,及出现的问题

    cmd输入安装selenium指令: pip install selenium 1.报错 Could not find a version that satisfies the requirement ...

  5. Docker搭建LNMP网站平台

    1.自定义网络 [root@linux-docker01 ~]# docker network create lnmp 67e7e0736b2c58f8f81eed50130803b34be0583f ...

  6. 软件测试:第二次作业(JUnit单元测试方法)

    一.JUnit是什么? JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework).JUnit测试是程序员测试, ...

  7. python调用c++ DLL

    python DLL = ctypes.cdll.LoadLibrary("./dll_file.so") #引入dllDLL.func(mat.ctypes.data // (1 ...

  8. wpf 命令

    上图为命令的 示例

  9. 删除csdn上面自己上传的资源

    今天想删掉以前的资源,才发现CSDN并没有提供删除资源的功能,然后去网上搜了下,这才删除了,不知道怎么删除的小伙伴看过来~ 首先,找到自己要删除资源的页面,举个栗子 https://download. ...

  10. 搭建vue的开发环境

    随手笔记:win7 64bit 1.安装node,直接从node官网下载,安装即可. 2.命令行输入 node -v 查看是否安装成功,显示node的版本号即安装成功.安装成功后,输入node,进入n ...