-
Notifications
You must be signed in to change notification settings - Fork 1
/
framework.scheduler.html
191 lines (157 loc) · 6.4 KB
/
framework.scheduler.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html dir="ltr" class="js desktop" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>framework.scheduler</title>
<script>
(function(H) {
H.className = H.className.replace(/\bno-js\b/, 'js')
})(document.documentElement)
</script>
<link rel="stylesheet" type="text/css" href="css.css">
<script type="text/javascript" charset="utf-8" src="js.js"></script>
</head>
<body>
<!--[if lte IE 7 ]><div id="IE7"><![endif]-->
<!--[if IE 8 ]><div id="IE8"><![endif]-->
<div id="dokuwiki__site">
<div id="dokuwiki__top" class="dokuwiki site mode_show ">
<!-- ********** HEADER ********** -->
<div id="dokuwiki__header">
<div class="pad group">
<hr class="a11y">
</div>
</div>
<!-- /header -->
<div class="wrapper group">
<!-- ********** CONTENT ********** -->
<div id="dokuwiki__content"><div class="pad group">
<div class="pageId"><span>zh_cn:api:framework.scheduler</span></div>
<div class="page group">
<!-- wikipage start -->
<!-- TOC START -->
<div id="dw__toc">
<h3 class="toggle">Table of Contents</h3>
<div>
<ul class="toc">
<li class="level1"><div class="li"><a href="#frameworkscheduler">framework.scheduler</a></div>
<ul class="toc">
<li class="level2"><div class="li"><a href="#schedulerscheduleupdateglobal">scheduler.scheduleUpdateGlobal</a></div></li>
<li class="level2"><div class="li"><a href="#schedulerscheduleglobal">scheduler.scheduleGlobal</a></div></li>
<li class="level2"><div class="li"><a href="#schedulerunscheduleglobal">scheduler.unscheduleGlobal</a></div></li>
<li class="level2"><div class="li"><a href="#schedulerperformwithdelayglobal">scheduler.performWithDelayGlobal</a></div></li>
</ul></li>
</ul>
</div>
</div>
<!-- TOC END -->
<h1 class="sectionedit1" id="frameworkscheduler">framework.scheduler</h1>
<div class="level1">
<p>
全局计时器、计划任务
</p>
<p>
<strong>«该模块在框架初始化时不会自动载入»</strong>
</p>
<hr />
</div>
<h2 class="sectionedit2" id="schedulerscheduleupdateglobal">scheduler.scheduleUpdateGlobal</h2>
<div class="level2">
<p>
计划一个全局帧事件回调,并返回该计划的句柄。
</p>
<p>
格式:
</p>
<pre class="code lua">handle <span class="sy0">=</span> scheduler<span class="sy0">.</span>scheduleUpdateGlobal<span class="br0">(</span>回调函数<span class="br0">)</span></pre>
<p>
全局帧事件在任何场景中都会执行,因此可以在整个应用程序范围内实现较为精确的全局计时器。
</p>
<p>
该函数返回的句柄用作 scheduler.unscheduleGlobal() 的参数,可以取消指定的计划。
</p>
<hr />
</div>
<h2 class="sectionedit3" id="schedulerscheduleglobal">scheduler.scheduleGlobal</h2>
<div class="level2">
<p>
计划一个以指定时间间隔执行的全局事件回调,并返回该计划的句柄。
</p>
<p>
格式:
</p>
<pre class="code lua">handle <span class="sy0">=</span> scheduler<span class="sy0">.</span>scheduleGlobal<span class="br0">(</span>回调函数<span class="sy0">,</span> 间隔时间<span class="br0">)</span></pre>
<p>
用法示例:
</p>
<pre class="code lua"><span class="kw1">local</span> <span class="kw1">function</span> onInterval<span class="br0">(</span>dt<span class="br0">)</span>
<span class="kw1">end</span>
<span class="co1">-- 每 0.5 秒执行一次 onInterval()</span>
<span class="kw1">local</span> handle <span class="sy0">=</span> scheduler<span class="sy0">.</span>scheduleGlobal<span class="br0">(</span>onInterval<span class="sy0">,</span> <span class="nu0">0.5</span><span class="br0">)</span></pre>
<hr />
</div>
<h2 class="sectionedit4" id="schedulerunscheduleglobal">scheduler.unscheduleGlobal</h2>
<div class="level2">
<p>
取消一个全局计划。
</p>
<p>
格式:
</p>
<pre class="code lua">scheduler<span class="sy0">.</span>unscheduleGlobal<span class="br0">(</span>句柄<span class="br0">)</span></pre>
<p>
scheduler.unscheduleGlobal() 的参数就是 scheduler.scheduleUpdateGlobal() 和 scheduler.scheduleGlobal() 的返回值。
</p>
<hr />
</div>
<h2 class="sectionedit5" id="schedulerperformwithdelayglobal">scheduler.performWithDelayGlobal</h2>
<div class="level2">
<p>
计划一个全局延时回调,并返回该计划的句柄。
</p>
<p>
格式:
</p>
<pre class="code lua">handle <span class="sy0">=</span> scheduler<span class="sy0">.</span>performWithDelayGlobal<span class="br0">(</span>回调函数<span class="sy0">,</span> 延迟时间<span class="br0">)</span></pre>
<p>
scheduler.performWithDelayGlobal() 会在等待指定时间后执行一次回调函数,然后自动取消该计划。
</p>
</div>
<!-- wikipage stop -->
</div>
<div class="docInfo">zh_cn/api/framework.scheduler.txt · Last modified: 2013/08/16 14:50 by Yu Lei Liao</div>
</div></div>
<!-- /content -->
<hr class="a11y">
<!-- PAGE ACTIONS -->
<div id="dokuwiki__pagetools">
<h3 class="a11y">Page Tools</h3>
<div class="tools">
<ul>
<li>
<a href="index.html" class="action backlink" rel="nofollow" title="home">
<span>home</span>
</a>
</li>
<li>
<a href="#dokuwiki__top" class="action top" accesskey="t" rel="nofollow" title="Back to top [T]">
<span>Back to top</span>
</a>
</li>
</ul>
</div>
</div>
</div>
<!-- /wrapper -->
</div>
</div>
<!-- /site -->
<div class="no">
<img src="zh_cn_api%20%5Bquick-cocos2d-x%20docs%5D_files/indexer.gif" alt="" height="1" width="2">
</div>
<div id="screen__mode" class="no"></div>
<!--[if ( lte IE 7 | IE 8 ) ]></div><![endif]-->
</body>
</html>