API Reference 0.7.1rikulo_effectEasingMotion

EasingMotion class

A fixed-duration motion constructed by an EasingFunction and a MotionAction.

class EasingMotion extends Motion {
 
 final MotionAction action;
 final EasingFunction easing;
 final int period, repeat, duration;
 
 /** Construct an EasingMotion.
  * 
  * + [easing] is the easing function. Default: linear.
  * + [period] is how long it takes to bring easing input from 0 to 1, in terms
  * of milliseconds. Default: 500 milliseconds.
  * + [repeat] is the number of times the motion repeats. If negative, the 
  * motion loops forever until [MotionAction] returns false. Default: 1.
  * + [start] is invoked when the motion starts.
  * + [end] is invoked when the motion ends.
  */
 EasingMotion(this.action, {EasingFunction easing, int period: 500, 
   int repeat: 1, MotionStart start, MotionEnd end}) : 
   this.easing = easing, this.period = period, this.repeat = repeat, 
   duration = repeat * period, super(start: start, end: end);
 
 /** Construct an EasingMotion by joining multiple EasingMotion.
  */
 EasingMotion.join(List<EasingMotion> motions, {EasingFunction easing, 
 int period: 500, int repeat: 1, MotionStart start, MotionEnd end}) :
 this(_jointAction(motions), easing: easing, period: period, repeat: repeat,
 start: _jointStart(motions, start), end: _jointEnd(motions, end));
 
 static MotionAction _jointAction(List<EasingMotion> motions) {
   return (num x, MotionState state) {
     for (EasingMotion em in motions)
       if (identical(em.action(x, state), false))
         return false;
   };
 }
 
 static MotionStart _jointStart(List<EasingMotion> motions, MotionStart start) {
   return (MotionState state) {
     if (start != null)
       start(state);
     for (EasingMotion em in motions)
       if (em._start != null)
         (em._start)(state);
   };
 }
 
 static MotionEnd _jointEnd(List<EasingMotion> motions, MotionEnd end) {
   return (MotionState state) {
     for (EasingMotion em in motions)
       if (em._end != null)
         (em._end)(state);
     if (end != null)
       end(state);
   };
 }
 
 /** Compute position value by [EasingFunction].
  */
 num doEasing_(num t) => easing != null ? easing(t) : t;
 
 /** Apply the position by [MotionAction];
  */
 bool doAction_(num x, MotionState state) => action(x, state);
 
 bool onMove(MotionState state) {
   final int runningTime = state.runningTime;
   final bool result = doAction_(doEasing_(_easingInput(runningTime)), state);
   return (repeat < 0 || runningTime < duration) && !identical(result, false);
 }
 
 num _easingInput(num runningTime) => 
     (duration < 0 || runningTime < duration) ? (runningTime / period) % 1 : 1;
 
 /** Skip to the end of motion.
  */
 void skip() {
   if (_state != null)
     doAction_(1, _state.._snapshot(new DateTime.now().millisecondsSinceEpoch));
   super.stop();
 }
 
}

Extends

Motion > EasingMotion

Subclasses

BuzzEffect, GlowEffect, HideEffect, LinearPathMotion, ShakeEffect, ShowEffect

Constructors

new EasingMotion(MotionAction action, {EasingFunction easing, int period: 500, int repeat: 1, MotionStart start, MotionEnd end}) #

Construct an EasingMotion.

  • easing is the easing function. Default: linear.
  • period is how long it takes to bring easing input from 0 to 1, in terms of milliseconds. Default: 500 milliseconds.

  • repeat is the number of times the motion repeats. If negative, the motion loops forever until MotionAction returns false. Default: 1.

  • start is invoked when the motion starts.
  • end is invoked when the motion ends.
EasingMotion(this.action, {EasingFunction easing, int period: 500, 
 int repeat: 1, MotionStart start, MotionEnd end}) : 
 this.easing = easing, this.period = period, this.repeat = repeat, 
 duration = repeat * period, super(start: start, end: end);

new EasingMotion.join(List<EasingMotion> motions, {EasingFunction easing, int period: 500, int repeat: 1, MotionStart start, MotionEnd end}) #

Construct an EasingMotion by joining multiple EasingMotion.

EasingMotion.join(List<EasingMotion> motions, {EasingFunction easing, 
int period: 500, int repeat: 1, MotionStart start, MotionEnd end}) :
this(_jointAction(motions), easing: easing, period: period, repeat: repeat,
start: _jointStart(motions, start), end: _jointEnd(motions, end));

Properties

final MotionAction action #

final MotionAction action

final Animator animator #

inherited from Motion

The Animator associated with the motion.

Animator get animator => _animator;

final int duration #

final int period, repeat, duration

final EasingFunction easing #

final EasingFunction easing

final bool isPaused #

inherited from Motion

Return true if the motion is at paused state.

bool get isPaused => _stateFlag == _MOTION_STATE_PAUSED;

final bool isRunning #

inherited from Motion

Return true if the motion is at running state.

bool get isRunning => _stateFlag == _MOTION_STATE_RUNNING;

final int period #

final int period

final int repeat #

final int period, repeat

final MotionState state #

inherited from Motion

Retrieve the current MotionState. null if not running.

MotionState get state => _state;

Methods

bool doAction_(num x, MotionState state) #

Apply the position by MotionAction;

bool doAction_(num x, MotionState state) => action(x, state);

num doEasing_(num t) #

Compute position value by EasingFunction.

num doEasing_(num t) => easing != null ? easing(t) : t;

void onEnd(MotionState state) #

inherited from Motion

Called after the runner returns false. Calling stop() will not invoke this function.

void onEnd(MotionState state) {
 if (_end != null)
   _end(state);
}

bool onMove(MotionState state) #

Called in each animator iteration, when the motion is at running state.

docs inherited from Motion
bool onMove(MotionState state) {
 final int runningTime = state.runningTime;
 final bool result = doAction_(doEasing_(_easingInput(runningTime)), state);
 return (repeat < 0 || runningTime < duration) && !identical(result, false);
}

void onPause(MotionState state) #

inherited from Motion

Called in the first animator iteration after the motion is paused.

void onPause(MotionState state) {}

void onResume(MotionState state) #

inherited from Motion

Called in the first animator iteration after the motion is resumed from pause.

void onResume(MotionState state) {}

void onStart(MotionState state) #

inherited from Motion

Called in the first animator iteration after the motion is added into animator.

void onStart(MotionState state) {
 if (_start != null)
   _start(state);
}

void pause() #

inherited from Motion

Pause the motion.

void pause() {
 if (_stateFlag != _MOTION_STATE_RUNNING)
   return;
 _stateFlag = _MOTION_STATE_PAUSED;
}

void run() #

inherited from Motion

Start the motion, or resume it from a pause.

void run() {
 switch (_stateFlag) {
   case _MOTION_STATE_RUNNING:
     return;
   case _MOTION_STATE_PAUSED:
     _stateFlag = _MOTION_STATE_RUNNING; // resume
     break;
   case _MOTION_STATE_INIT:
     animator.add(this._task);
     break;
 }
}

void skip() #

Skip to the end of motion.

void skip() {
 if (_state != null)
   doAction_(1, _state.._snapshot(new DateTime.now().millisecondsSinceEpoch));
 super.stop();
}

void stop() #

inherited from Motion

Stop the motion and reset the internal states.

void stop() {
 animator.remove(this._task);
 _state = null;
 _stateFlag = _MOTION_STATE_INIT;
}