Merge pull request #15348 from minggo/action_issue

some bugs fixed of Repeat
This commit is contained in:
minggo 2016-03-31 14:47:54 +08:00
commit 5f4e8a65c4
1 changed files with 13 additions and 8 deletions

View File

@ -409,10 +409,11 @@ bool Repeat::initWithAction(FiniteTimeAction *action, unsigned int times)
_actionInstant = dynamic_cast<ActionInstant*>(action) ? true : false; _actionInstant = dynamic_cast<ActionInstant*>(action) ? true : false;
//an instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action //an instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action
if (_actionInstant) // minggo: instant action doesn't execute action in Repeat::startWithTarget(), so comment it.
{ // if (_actionInstant)
_times -=1; // {
} // _times -=1;
// }
_total = 0; _total = 0;
return true; return true;
@ -455,7 +456,7 @@ void Repeat::update(float dt)
{ {
if (dt >= _nextDt) if (dt >= _nextDt)
{ {
while (dt > _nextDt && _total < _times) while (dt >= _nextDt && _total < _times)
{ {
if (!(sendUpdateEventToScript(1.0f, _innerAction))) if (!(sendUpdateEventToScript(1.0f, _innerAction)))
_innerAction->update(1.0f); _innerAction->update(1.0f);
@ -467,8 +468,11 @@ void Repeat::update(float dt)
} }
// fix for issue #1288, incorrect end value of repeat // fix for issue #1288, incorrect end value of repeat
if(dt >= 1.0f && _total < _times) if(fabs(dt - 1.0f) < FLT_EPSILON && _total < _times)
{ {
if (!(sendUpdateEventToScript(1.0f, _innerAction)))
_innerAction->update(1.0f);
_total++; _total++;
} }
@ -477,8 +481,9 @@ void Repeat::update(float dt)
{ {
if (_total == _times) if (_total == _times)
{ {
if (!(sendUpdateEventToScript(1, _innerAction))) // minggo: inner action update is invoked above, don't have to invoke it here
_innerAction->update(1); // if (!(sendUpdateEventToScript(1, _innerAction)))
// _innerAction->update(1);
_innerAction->stop(); _innerAction->stop();
} }
else else