1. member variables
Repeat:
unsigned int _times; // the Create parameters unsigned int _Total; // number of executed float _nextDt; // startWithTarget calculation, the current time all action executed proportion of the total time, schedule the next turn Repeat needed BOOL _actionInstant; // create instantaneous determination of whether Action FiniteTimeAction * _innerAction; // create parameters
RepeatForever:
ActionInterval * _innerAction; // the Create parameters
2. create
Repeat::create(FiniteTimeAction *action, unsigned int times) RepeatForever::create(ActionInterval *action)
Repeat:
After two members of the variable assignment parameter to determine whether the action is instantaneous action:
ActionInterval :: initWithDuration (d) // when the operation frequency and a long operation *
_actionInstant of dynamic_cast = <ActionInstant *> (Action)? To true : to false ;
_Total = 0;
RepeatForever: action parameter set variables.
3. start with target
Repeat:
= _Total 0 ; _nextDt = _innerAction-> getDuration () / _duration; // a proportion of total time action ActionInterval :: startWithTarget (target); _innerAction -> startWithTarget (target);
RepeatForever:
ActionInterval::startWithTarget(target);
_innerAction->startWithTarget(target);
4. update
RepeatForever no update method. Each frame, RepeatForever step method calls the action step.
Repeat:
Briefly, if the current progress is not progress to the next Repeat the trigger, continue this unfinished update. To trigger the next Repeat progress, first to complete the implementation of this Repeat, Repeat next action is to initialize and calculated to trigger progress at the next Repeat. If the total number of times, stop the current action, otherwise perform the action update.
void Repeat :: Update ( float dt) { IF (dt> = _nextDt) // current progress to reach the next Repeat trigger progress { the while (dt> = _nextDt && _Total <_times) // arrive at times Repeat trigger progress and the number of executions not required to enter circulation { IF ((sendUpdateEventToScript (! 1.0f , _innerAction))) _innerAction -> Update ( 1.0f ); // execute Action _Total ++; // perform well, the number of +1 _innerAction -> STOP () ; _innerAction -> startWithTarget (_target); //Reinitialize Action _nextDt = _innerAction-> getDuration () / * _ DURATION (_Total + . 1 ); // Set to trigger a new schedule of Repeat } // ... IF (! _ActionInstant) // can not be instantaneous action { IF (_Total _times ==) // reaching the total number of restrictions { _innerAction-> STOP (); } the else { IF ((sendUpdateEventToScript (dt - (_nextDt - _innerAction-> getDuration () /! _duration), _innerAction))) _innerAction -> Update (dt - (_nextDt - _innerAction-> getDuration () /_duration)); // execute } } } the else // not progress to the next trigger once Repeat to continue to implement this Repeat of Action { IF ((sendUpdateEventToScript (fmodf (dt * _times,! 1.0f ))), _innerAction) _innerAction -> Update (the fmodf (dt * _times, 1.0f )); // parameters for the current Repeat progress } }