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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM