Home > Database > Mysql Tutorial > cocos2dx schedule可延时的for循环 scheduleonce的问题

cocos2dx schedule可延时的for循环 scheduleonce的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:32:18
Original
1590 people have browsed it

scheduleonce 只执行一次的时间函数,可以看做延迟执行。 今天想用scheduleonce做一个延迟的for循环 大体思路如下: //全局 int i=1; scheduleF(0.5f);//调用 //时间函数 void hello::scheduleF(float f) { if(i10) { …… scheduleonce (schedule_selector(

scheduleonce 只执行一次的时间函数,可以看做延迟执行。

今天想用scheduleonce做一个延迟的for循环

大体思路如下:

//全局

int i=1;

scheduleF(0.5f);//调用

//时间函数

void hello::scheduleF(float f)

{

if(i

{

……

scheduleonce(schedule_selector(hello::scheduleF),0.3f);

}

i++;

}

试了一下,不行,最多执行到i=2,应该是手动调用一次,scheduleonce第一次可以。

所以我觉得可能是scheduleonce已经添加过这个函数了,不能多次添加,于是想在添加之前un一下,但是没找到unscheduleonce这个方法,用了unschedule,测试还是不行。

无奈全部换成了schedule,unschedule

void hello::scheduleF(float f)

{

if(i

{

……

unschedule(schedule_selector(hello::scheduleF));

schedule(schedule_selector(hello::scheduleF),0.3f);

}

else

{

unschedule(schedule_selector(hello::scheduleF));

}

i++;

}

这样就行了,不过遗漏unscheduleonce这个方法,不知是不是漏洞····


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template