Egret_时间与运行
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_时间与运行的更多相关文章
- 针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行
<?php//针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行,http://ken.01h.net/define('PHP_LOCK_FILE', dirname(__FILE__ ...
- 如何用Qt写一个同一时间只能运行一个实例的应用程序
http://blog.sina.com.cn/s/blog_6343941a0100nk2x.html 可以达到的目的: 1.应用只启动一个实例,依赖于QtNetwork模块 2.启动时向另一个实例 ...
- APP长时间后台运行
* 参考:http://www.nivalxer.com/archives/187 首先,我要说明的是在iOS中,一般应用程序在后台挂起之后仅拥有3分钟时间来处理相应的未完成事件,但是3分钟之后就会 ...
- Android长时间后台运行Service
项目需要在后台获取GPS经纬度.当用户对手机有一段时间没有操作后,屏幕(Screen)将从高亮(Bright)变为暗淡(Dim),如果再过段时间没操作, 屏幕(Screen)将又由暗淡(Di ...
- C# 给某个方法设定执行超时时间 C#如何控制方法的执行时间,超时则强制退出方法执行 C#函数运行超时则终止执行(任意参数类型及参数个数通用版)
我自己写的 /// <summary> /// 函数运行超时则终止执行(超时则返回true,否则返回false) /// </summary> /// <typepara ...
- uptime - 告知系统运行了多久时间
SYNOPSIS(总览) uptime uptime [-V] DESCRIPTION(描述) uptime 给出下列信息的一行显示. 当前时间, 系统运行了多久时间, 当前登陆的用户有多少, 以及前 ...
- iOS---后台运行机制详解
一.iOS的“伪后台”程序 首先,先了解一下iOS 中所谓的「后台进程」到底是怎么回事吧? Let me be as clear as I can be: the iOS multitasking b ...
- 通过监控线程状态来保证socket服务器的稳定运行
云平台中使用的socket服务器是我们自己定义一套通信协议,并通过C#实现的一个socket服务. 该服务目前是和web服务一起运行在IIS容器中,通过启动一个永不退出的新线程来监听端口. 在开发的初 ...
- SQL Server时间粒度系列----第7节日历数据表详解
本文目录列表: 1.时间粒度有关描述 2.时间维度有关功能函数3.日历数据表 4.日历数据表数据填充 5.总结语 6.参考清单列表 时间粒度有关描述 将该系列涉及到的时间粒度以及分钟以下的粒度 ...
随机推荐
- Fortran与C/C++混合编程示例
以下例子均来自网络,只是稍作了编辑,方便今后查阅. 子目录 (一) Fortran调用C语言 (二) C语言调用Fortran (三) C++ 调用Fortran (四) Fortran 调用 C++ ...
- lr12关联,响应乱码
1.前程贷登录.投标脚本 Action() { // web_url("登录页", // "URL=http://120.78.128.25:8765 ...
- linux网络编程基础--(转自网络)
转自 http://www.cnblogs.com/MyLove-Summer/p/5215287.html Linux下的网络编程指的是socket套接字编程,入门比较简单. 1. socket套接 ...
- [宽度优先搜索] FZU-2150 Fire Game
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...
- jenkins 关闭和重启的实现
jerkins自带的重启手段重启过程缓慢,在jenkins的操作过程中可使用以下操作: 关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit.例如我jenkins的地址h ...
- JVM CUP占用率过高排除方法,windows环境
jdk自带的jvisualvm可以看到程序CPU使用率,但是无法确定具体的线程,想要确定到具体的线程需要借用到微软的Process Explorer 具体排除方法: 一:打开资源管理器,找到cup占用 ...
- hadoop sentry错误记录
1.报无法实例化metastore连接 hive> show tables; FAILED: SemanticException org.apache.hadoop.hive.ql.metada ...
- c#分布式ID生成器
c#分布式ID生成器 简介 这个是根据twitter的snowflake来写的.这里有中文的介绍. 如上图所示,一个64位ID,除了最左边的符号位不用(固定为0,以保证生成的ID都是正数),还剩余 ...
- Mac下安装Fiddler
Mac下安装Fiddler 1.Mono安装 安装程序可以从http://www.mono-project.com/download地址下载. 安装完成后,打开Terminal终端,在terminal ...
- 程序执行流程:猜数字游戏;库的使用:turtle
>>> import turtle >>> turtle.circle(50) >>> turtle.circle(100) Python 3.6 ...