程序之路

Cocos Creator 定时器的使用

2019-01-15  本文已影响0人  kingURL

以下是Ts代码:

''' 
    this.mIndex = 0;
    let funUp = function () {
        if (Index <= this.mIndex) {
            this.unschedule(funUp);
        }
    }
    this.schedule(funUp, newTime);
'''

条件一: 这个this.schedule(funUp, newTime); 是要写到一个继承组件的类的地方.
条件二: 回调函数必须写成 let fun = function {...} 这样,才可以触发 this.unschedule(funDown) 这个,停止循环.

最后标注一下,停止循环 unschedule 传的参数是回调函数,这个很奇特.

上一篇 下一篇

猜你喜欢

热点阅读