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. 【转】Oracle系列导航目录

    .Net程序员学用Oracle系列(1):导航目录 .Net程序员学用Oracle系列(2):准备测试环境 .Net程序员学用Oracle系列(3):数据库编程规范 .Net程序员学用Oracle系列 ...

  2. learning websocket protocol

    websocket的产生背景: 众所周知,Web应用的通信过程通常是客户端通过浏览器发出一个请求,服务器端接收请求后进行处理并返回结果给客户端,客户端浏览器将信息呈现.这种机制对于信息变化不是特别频繁 ...

  3. HTML特殊字符编码对照表(备记)

    特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码 Α Α Α Β Β Β Γ Γ Γ Δ Δ Δ Ε Ε Ε Ζ Ζ Ζ Η Η Η Θ Θ Θ Ι Ι ...

  4. python修炼第五天

    第五天,感觉开始烧脑了.递归逻辑难,模块数量多,但是绝世武功都是十年磨一剑出来的!稳住! 1 递归. 定义-----递归就是在函数的内部调用自己递归深度 998不建议修改递归深度,因为如果998都没有 ...

  5. ios打包unity应用以及配置签名

    先决条件是必须为苹果mac机.拥有公司苹果账号,并确保电脑上安装了unity,unity包 ios-support.和xcode. 1.打开了unity应用之后,选择buildSettings 然后点 ...

  6. <转载> UE4的Actor类C++简单尝试

    原文链接:   简书小小酥XX https://www.jianshu.com/p/2bcc80f0e789 一开始我用了一段时间UE4,发现如果用蓝图系统真的不太适合我的风格.因为之前一直都是用Un ...

  7. 编译安装LAMP

    编译安装MariaDB 创建MariaDB安装目录.数据库存放目录.建立用户和目录 先创建一个名为mysql且没有登录权限的用户和一个名为mysql的用户组,然后安装mysql所需的依赖库和依赖包,最 ...

  8. 记录配置xshell显示中文乱码的一次巧合

    linux系统设置了中文UTF8,xshell终端也设置了中文UTF8,但xshell仍然无法显示中文,于是想起可能是字体显示问题. 设置楷体字体后,虽然文字方向还有问题,但乱码显示的问题解决了,方向 ...

  9. numpy数组及处理:效率对比

    def Sum(n): #定义一个函数(注意:格式对齐,否则会出错) a=list(range(n)) b=list(range(0,50000*n,5)) c=[] for i in range(l ...

  10. Ubuntu 中文拼音输入法键入异常

    如果确定系统装的OK,可以修复ubuntu Ctrl+Alt+t切出终端,输入命令:  " ibus-daemon -drx",然后再输入拼音试一试就会OK .