mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Implement View#pause() and View#play() to start and stop animation.
This commit is contained in:
parent
6e5d8939d5
commit
696b5f29b9
1 changed files with 30 additions and 11 deletions
|
@ -128,9 +128,10 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
DomEvent.remove(window, this._windowHandlers);
|
||||
/*#*/ } // __options.environment == 'browser'
|
||||
this._element = this._project = null;
|
||||
// Removing all onFrame handlers makes the onFrame handler stop
|
||||
// automatically through its uninstall method.
|
||||
// Remove all onFrame handlers.
|
||||
// TODO: Shouldn't we remove all handlers, automatically
|
||||
this.detach('frame');
|
||||
this._animate = false;
|
||||
this._frameItems = {};
|
||||
return true;
|
||||
},
|
||||
|
@ -146,17 +147,11 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
*/
|
||||
onFrame: {
|
||||
install: function() {
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
this._animate = true;
|
||||
// Request a frame handler straight away to initialize the
|
||||
// sequence of onFrame calls.
|
||||
if (!this._requested)
|
||||
this._requestFrame();
|
||||
/*#*/ } // __options.environment == 'browser'
|
||||
this.play();
|
||||
},
|
||||
|
||||
uninstall: function() {
|
||||
this._animate = false;
|
||||
this.pause();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -397,7 +392,31 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
},
|
||||
|
||||
/**
|
||||
* Updates the view if there are changes.
|
||||
* Makes all animation play by adding the view to the request animation
|
||||
* loop.
|
||||
*/
|
||||
play: function() {
|
||||
this._animate = true;
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
// Request a frame handler straight away to initialize the
|
||||
// sequence of onFrame calls.
|
||||
if (!this._requested)
|
||||
this._requestFrame();
|
||||
/*#*/ } // __options.environment == 'browser'
|
||||
},
|
||||
|
||||
/**
|
||||
* Makes all animation pause by removing the view to the request animation
|
||||
* loop.
|
||||
*/
|
||||
pause: function() {
|
||||
this._animate = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the view if there are changes. Note that when using built-in
|
||||
* event hanlders for interaction, animation and load events, this method is
|
||||
* invoked for you automatically at the end.
|
||||
*
|
||||
* @name View#update
|
||||
* @function
|
||||
|
|
Loading…
Reference in a new issue