Animator
Animator.
Example
include "lib://core/animation/animator.ms" // transition class var win = new Moscrif.Window(); // main window object var quit = false; // set quit to true for application exit win._animate = function() { var showNew = new Animator({ transition: Animator.Transition.veryBouncy, duration: 3500, // length of animation in miliseconds }); showNew.addSubject(function(state) { // state starts from 0.0 to 0.1 this super._newTop = (this super._newImage.height * (state - 1)).toInteger(); win.invalidate(); }) // show new image showNew.play(); } win.onStart = function() { // load bitmaps this._oldImage = Bitmap.fromFile("app://old.jpg"); this._newImage = Bitmap.fromFile("app://new.png"); // position for both bitmaps this._newTop = -1*this._newImage.height; // start animation after 2 seconds var timer = new Timer(100, false); // interval make no sense here timer.start(1000); timer.onTick = function(sender) { this super._animate(); }; } win.onDraw = function(s, c) { c.drawBitmap(this._oldImage, 0, 0); c.drawBitmap(this._newImage, 0, this._newTop); } win.onProcess = function() { return 1; } win.init().run();
Properties
-
duration : Integer
Length of animation in miliseconds.
-
transition : Object
Transition .
Methods
-
addSubject(subject) : Animator
Add a function or an object with a method setState(state) that will be called with a number between 0 and 1 on each frame of the animation
-
applyDefaults(defaults, prefs)
Merge the properties of two objects.
-
clearSubjects()
Remove all subjects.
-
jumpTo(to, propagate = true)
Animate from the current state to provided value.
-
makeADSR(attackEnd, decayEnd, sustainEnd, sustainLevel) : Function
Make an Attack Decay Sustain Release envelope that starts and finishes on the same level.
-
makeBounce(bounces) : Function
Make a transition function that, like a ball falling to floor, reaches the target and bounces back again.
-
makeEaseIn(a) : Function
Make a transition function that gradually accelerates. pass a=1 for smooth gravitational acceleration, higher values for an exaggerated effect.
-
makeEaseOut(a) : Function
As makeEaseIn but for decelerations.
-
makeElastic(bounces) : Function
Make a transition function that, like an object with momentum being attracted to a point, goes past the target then returns.
-
onTimerEvent()
Called once per frame to update the current state.
-
play()
Play animation.
-
propagate()
Forward the current state to the animation subjects.
-
reverse()
Reverse animation.
-
seekFromTo(from, to)
Animate from the current state to provided value.
-
seekTo(to)
Animate from the current state to provided value.
-
setOptions(options)
Apply default options.
-
stop()
Stop animation.
-
this(options = {}) : Animator
Creates new instance of Animator class.
-
toggle()
Seek to the opposite of the current target.
Events
-
onComplete()
This function is called, when body needs to be redrawn.
-
onStep()
This function is called, when body needs to be redrawn.