From 393af19237c928de28dca59ca14f2fb22e7dd040 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Wed, 26 Aug 2015 23:41:48 +0800 Subject: [PATCH] [Node::scheduleOnce]Fixed the callback will be executed multiple times if the value of delay equal zero. --- cocos/base/CCScheduler.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cocos/base/CCScheduler.cpp b/cocos/base/CCScheduler.cpp index 0acc1d3b93..7977dfff65 100644 --- a/cocos/base/CCScheduler.cpp +++ b/cocos/base/CCScheduler.cpp @@ -130,19 +130,15 @@ void Timer::update(float dt) trigger(interval); _elapsed -= interval; _timesExecuted += 1; - if (_elapsed <= 0.f) + + if (!_runForever && _timesExecuted > _repeat) { + cancel(); break; } - if (_runForever) + if (_elapsed <= 0.f) { - continue; - } - - if (_timesExecuted > _repeat) - { //unschedule timer - cancel(); break; } }