Phaser的timer用法
1. 延迟timer,相当于setTimeout
game.time.events.add(Phaser.Timer.SECOND*5,this.delayOver,this);
2. 循环timer,相当于setInterval
game.time.events.loop(Phaser.Timer.SECOND,this.addMonster,this);
3. 停止一个timer
this.monsterTimer = game.time.events.loop(Phaser.Timer.SECOND,this.addMonster,this);
game.time.events.remove(this.monsterTimer);
4. Phaser中的时间常量
Phaser.Timer.SECOND =1 second
Phaser.Timer.SECOND*5 =5 seconds
Phaser.Timer.SECOND/2= half a second or call the function twice a second
Phaser.Timer.SECOND/10 =one tenth a second
5. 创建一个倒计时的例子
var StateMain = {
preload: function() {},
create: function() {
//total time until trigger
this.timeInSeconds = 120;
//make a text field
this.timeText = game.add.text(game.world.centerX, game.world.centerY, "0:00");
//turn the text white
this.timeText.fill = "#ffffff";
//center the text
this.timeText.anchor.set(0.5, 0.5);
//set up a loop timer
this.timer = game.time.events.loop(Phaser.Timer.SECOND, this.tick, this);
},
tick: function() {
//subtract a second
this.timeInSeconds--;
//find how many complete minutes are left
var minutes = Math.floor(this.timeInSeconds / 60);
//find the number of seconds left
//not counting the minutes
var seconds = this.timeInSeconds - (minutes * 60);
//make a string showing the time
var timeString = this.addZeros(minutes) + ":" + this.addZeros(seconds);
//display the string in the text field
this.timeText.text = timeString;
//check if the time is up
if (this.timeInSeconds == 0) {
//remove the timer from the game
game.time.events.remove(this.timer);
//call your game over or other code here!
this.timeText.text="Game Over";
}
},
/**
* add leading zeros to any number less than 10
* for example turn 1 to 01
*/
addZeros: function(num) {
if (num < 10) {
num = "0" + num;
}
return num;
},
update: function() {}
}
出处:https://phasergames.com/phaser-timer-basics-tutorial/
Phaser的timer用法的更多相关文章
- C# Timer用法及实例详解
C# Timer用法有哪些呢?我们在使用C# Timer时都会有自己的一些总结,那么这里向你介绍3种方法,希望对你了解和学习C# Timer使用的方法有所帮助. 关于C# Timer类 在C#里关于 ...
- C# Timer用法及实例讲解
摘自:http://www.cnblogs.com/xcsn/archive/2013/05/10/3070485.html 1.C# Timer用法及实例详解 http://developer.51 ...
- Android Timer用法
Android考虑到线程安全问题,不允许在线程中执行UI线程,在Android中,有一个类:android.os.Handler,这个可以实现各处线程间的消息传递.先看段代码,这个实例化了一个Hand ...
- Winform Timer用法,Invoke在Timer的事件中更新控件状态
System.Timers.Timer可以定时执行方法,在指定的时间间隔之后执行事件. form窗体上放一个菜单,用于开始或者结束定时器Timer. 一个文本框,显示定时执行方法. public pa ...
- Threading.Timer用法
protected System.Threading.Timer executeTimer;//定时器 private int interval;//定时器执行间隔周期 executeTimer = ...
- java之定时器任务Timer用法
在项目开发中,经常会遇到需要实现一些定时操作的任务,写过很多遍了,然而每次写的时候,总是会对一些细节有所遗忘,后来想想可能是没有总结的缘故,所以今天小编就打算总结一下可能会被遗忘的小点: 1. pub ...
- C# 定时执行方法: System.Timers.Timer用法示例
System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒 private void Form1_Load(ob ...
- 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...
- System.Timers.Timer用法
System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒 private void Form1_Load(object se ...
随机推荐
- stata操作
//stata操作 *************************数据基本操作****************************** gen varname = value //定义变量 r ...
- python查询mysql数据
>>>cur.execute("select * from 表名") >>>lines=cur.fetchall() >>>f ...
- python与mysql的连接过程
1.cmd---pip3 install PyMySQL2.>>>import pymysql3.mysql>create database bookdb character ...
- python2.7练习小例子(十五)
15):题目:输出指定格式的日期. 程序分析:使用 datetime 模块. 程序源代码: #!/usr/bin/python # -*- coding: UTF-8 -*- ...
- 使用USB Key(加密狗)实现身份认证
首先你需要去买一个加密狗设备,加密狗是外形酷似U盘的一种硬件设备! 这里我使用的坚石诚信公司的ET99产品 公司项目需要实现一个功能,就是客户使用加密狗登录, 客户不想输入任何密码之类的东西,只需要插 ...
- JVM运行内存分配和回收
本文来自网易云社区 作者:吕宗胜 Java语言与C语言相比,最大的特点是编程人员无需过多的关心Java的内存分配和回收,因为所有这一切,Java的虚拟机都帮我们实现了.JVM的内存管理,大大降低了开发 ...
- Chrome也疯狂之Vimium插件
Chrome也疯狂之安装Vimium插件 由于最近换上了Mac,深感外设的累赘,脱离了外接鼠标以及键盘之后发现操作更加的流畅了(可怜我入手不到一年的机械键盘).当然脱离鼠标用触摸板来操作浏览器有时候还 ...
- abo dto属性验证的坑
问题回现: public class ShipmentRequestDto { public string FromPhoneNumber { get; set; } /// <summary& ...
- python,批量生成指定格式的审核数据(传输参数格式为数组时)
#思路#获取list长度(例如列表有20条数据,则生成20条数据),生成数组长度为list元素的数据,完成对列表20条数据的批量审核def createBatchData(self,str_in,li ...
- 孤荷凌寒自学python第七十天学习并实践beautifulsoup对象用法3
孤荷凌寒自学python第七十天学习并实践beautifulsoup对象用法3 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步了 ...