@@ -11,16 +11,18 @@ var TWEEN_CONST = require('./const');
1111
1212/**
1313 * @classdesc
14- * [description]
14+ * A Tween is able to manipulate the properties of one or more objects to any given value, based
15+ * on a duration and type of ease. They are rarely instantiated directly and instead should be
16+ * created via the TweenManager.
1517 *
1618 * @class Tween
1719 * @memberof Phaser.Tweens
1820 * @constructor
1921 * @since 3.0.0
2022 *
21- * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline) } parent - [description]
22- * @param {Phaser.Tweens.TweenDataConfig[] } data - [description]
23- * @param {array } targets - [description]
23+ * @param {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline) } parent - A reference to the parent of this Tween. Either the Tween Manager or a Tween Timeline instance.
24+ * @param {Phaser.Tweens.TweenDataConfig[] } data - An array of TweenData objects, each containing a unique property to be tweened.
25+ * @param {array } targets - An array of targets to be tweened.
2426 */
2527var Tween = new Class ( {
2628
@@ -29,7 +31,8 @@ var Tween = new Class({
2931 function Tween ( parent , data , targets )
3032 {
3133 /**
32- * [description]
34+ * A reference to the parent of this Tween.
35+ * Either the Tween Manager or a Tween Timeline instance.
3336 *
3437 * @name Phaser.Tweens.Tween#parent
3538 * @type {(Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline) }
@@ -56,7 +59,7 @@ var Tween = new Class({
5659 this . data = data ;
5760
5861 /**
59- * data array doesn't change, so we can cache the length
62+ * The cached length of the data array.
6063 *
6164 * @name Phaser.Tweens.Tween#totalData
6265 * @type {integer }
@@ -65,7 +68,7 @@ var Tween = new Class({
6568 this . totalData = data . length ;
6669
6770 /**
68- * An array of references to the target/s this Tween is operating on
71+ * An array of references to the target/s this Tween is operating on.
6972 *
7073 * @name Phaser.Tweens.Tween#targets
7174 * @type {object[] }
@@ -83,7 +86,7 @@ var Tween = new Class({
8386 this . totalTargets = targets . length ;
8487
8588 /**
86- * If true then duration, delay, etc values are all frame totals.
89+ * If ` true` then duration, delay, etc values are all frame totals.
8790 *
8891 * @name Phaser.Tweens.Tween#useFrames
8992 * @type {boolean }
@@ -105,7 +108,7 @@ var Tween = new Class({
105108
106109 /**
107110 * Loop this tween? Can be -1 for an infinite loop, or an integer.
108- * When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD)
111+ * When enabled it will play through ALL TweenDatas again. Use TweenData.repeat to loop a single element.
109112 *
110113 * @name Phaser.Tweens.Tween#loop
111114 * @type {number }
@@ -289,7 +292,7 @@ var Tween = new Class({
289292 * @method Phaser.Tweens.Tween#getValue
290293 * @since 3.0.0
291294 *
292- * @return {number } [description]
295+ * @return {number } The value of the Tween.
293296 */
294297 getValue : function ( )
295298 {
@@ -304,7 +307,7 @@ var Tween = new Class({
304307 *
305308 * @param {number } value - The scale factor for timescale.
306309 *
307- * @return {Phaser.Tweens.Tween } This Tween object .
310+ * @return {this } - This Tween instance .
308311 */
309312 setTimeScale : function ( value )
310313 {
@@ -358,29 +361,34 @@ var Tween = new Class({
358361 * @method Phaser.Tweens.Tween#hasTarget
359362 * @since 3.0.0
360363 *
361- * @param {object } target - [description]
364+ * @param {object } target - The target to check against this Tween.
362365 *
363- * @return {boolean } [description]
366+ * @return {boolean } `true` if the given target is a target of this Tween, otherwise `false`.
364367 */
365368 hasTarget : function ( target )
366369 {
367370 return ( this . targets . indexOf ( target ) !== - 1 ) ;
368371 } ,
369372
370373 /**
371- * [description]
374+ * Updates the value of a property of this Tween to a new value, without adjusting the
375+ * Tween duration or current progress.
376+ *
377+ * You can optionally tell it to set the 'start' value to be the current value (before the change).
372378 *
373379 * @method Phaser.Tweens.Tween#updateTo
374380 * @since 3.0.0
375381 *
376- * @param {string } key - [description]
377- * @param {* } value - [description]
378- * @param {boolean } startToCurrent - [description]
382+ * @param {string } key - The property to set the new value for.
383+ * @param {* } value - The new value of the property.
384+ * @param {boolean } [ startToCurrent=false] - Should this change set the start value to be the current value?
379385 *
380- * @return {Phaser.Tweens.Tween } This Tween object .
386+ * @return {this } - This Tween instance .
381387 */
382388 updateTo : function ( key , value , startToCurrent )
383389 {
390+ if ( startToCurrent === undefined ) { startToCurrent = false ; }
391+
384392 for ( var i = 0 ; i < this . totalData ; i ++ )
385393 {
386394 var tweenData = this . data [ i ] ;
@@ -406,6 +414,8 @@ var Tween = new Class({
406414 *
407415 * @method Phaser.Tweens.Tween#restart
408416 * @since 3.0.0
417+ *
418+ * @return {this } This Tween instance.
409419 */
410420 restart : function ( )
411421 {
@@ -419,10 +429,12 @@ var Tween = new Class({
419429 this . stop ( ) ;
420430 this . play ( ) ;
421431 }
432+
433+ return this ;
422434 } ,
423435
424436 /**
425- * [description]
437+ * Internal method that calculates the overall duration of the Tween.
426438 *
427439 * @method Phaser.Tweens.Tween#calcDuration
428440 * @since 3.0.0
@@ -533,7 +545,7 @@ var Tween = new Class({
533545 } ,
534546
535547 /**
536- * [description]
548+ * Internal method that advances to the next state of the Tween during playback.
537549 *
538550 * @method Phaser.Tweens.Tween#nextState
539551 * @since 3.0.0
@@ -588,12 +600,12 @@ var Tween = new Class({
588600 } ,
589601
590602 /**
591- * [description]
603+ * Pauses the Tween immediately. Use `resume` to continue playback.
592604 *
593605 * @method Phaser.Tweens.Tween#pause
594606 * @since 3.0.0
595607 *
596- * @return {Phaser.Tweens.Tween } This Tween object .
608+ * @return {this } - This Tween instance .
597609 */
598610 pause : function ( )
599611 {
@@ -612,18 +624,22 @@ var Tween = new Class({
612624 } ,
613625
614626 /**
615- * [description]
627+ * Starts a Tween playing.
628+ *
629+ * You only need to call this method if you have configured the tween to be paused on creation.
616630 *
617631 * @method Phaser.Tweens.Tween#play
618632 * @since 3.0.0
619633 *
620- * @param {boolean } resetFromTimeline - [description]
634+ * @param {boolean } resetFromTimeline - Is this Tween being played as part of a Timeline?
635+ *
636+ * @return {this } This Tween instance.
621637 */
622638 play : function ( resetFromTimeline )
623639 {
624640 if ( this . state === TWEEN_CONST . ACTIVE )
625641 {
626- return ;
642+ return this ;
627643 }
628644 else if ( this . state === TWEEN_CONST . PENDING_REMOVE || this . state === TWEEN_CONST . REMOVED )
629645 {
@@ -677,15 +693,17 @@ var Tween = new Class({
677693
678694 this . parent . makeActive ( this ) ;
679695 }
696+
697+ return this ;
680698 } ,
681699
682700 /**
683- * [description]
701+ * Internal method that resets all of the Tween Data, including the progress and elapsed values.
684702 *
685703 * @method Phaser.Tweens.Tween#resetTweenData
686704 * @since 3.0.0
687705 *
688- * @param {boolean } resetFromLoop - [description]
706+ * @param {boolean } resetFromLoop - Has this method been called as part of a loop?
689707 */
690708 resetTweenData : function ( resetFromLoop )
691709 {
@@ -728,7 +746,7 @@ var Tween = new Class({
728746 * @method Phaser.Tweens.Tween#resume
729747 * @since 3.0.0
730748 *
731- * @return {Phaser.Tweens.Tween } This Tween object .
749+ * @return {this } - This Tween instance .
732750 */
733751 resume : function ( )
734752 {
@@ -747,12 +765,14 @@ var Tween = new Class({
747765 } ,
748766
749767 /**
750- * [description]
768+ * Attempts to seek to a specific position in a Tween.
751769 *
752770 * @method Phaser.Tweens.Tween#seek
753771 * @since 3.0.0
754772 *
755- * @param {number } toPosition - A value between 0 and 1.
773+ * @param {number } toPosition - A value between 0 and 1 which represents the progress point to seek to.
774+ *
775+ * @return {this } This Tween instance.
756776 */
757777 seek : function ( toPosition )
758778 {
@@ -811,29 +831,24 @@ var Tween = new Class({
811831
812832 tweenData . current = tweenData . start + ( ( tweenData . end - tweenData . start ) * v ) ;
813833
814- // console.log(tweenData.key, 'Seek', tweenData.target[tweenData.key], 'to', tweenData.current, 'pro', tweenData.progress, 'marker', toPosition, progress);
815-
816- // if (tweenData.current === 0)
817- // {
818- // console.log('zero', tweenData.start, tweenData.end, v, 'progress', progress);
819- // }
820-
821834 tweenData . target [ tweenData . key ] = tweenData . current ;
822835 }
836+
837+ return this ;
823838 } ,
824839
825840 /**
826- * [description]
841+ * Sets an event based callback to be invoked during playback.
827842 *
828843 * @method Phaser.Tweens.Tween#setCallback
829844 * @since 3.0.0
830845 *
831846 * @param {string } type - Type of the callback.
832847 * @param {function } callback - Callback function.
833848 * @param {array } [params] - An array of parameters for specified callbacks types.
834- * @param {object } [scope] - [description]
849+ * @param {object } [scope] - The context the callback will be invoked in.
835850 *
836- * @return {Phaser.Tweens.Tween } This Tween object .
851+ * @return {this } This Tween instance .
837852 */
838853 setCallback : function ( type , callback , params , scope )
839854 {
@@ -854,6 +869,8 @@ var Tween = new Class({
854869 * @since 3.2.0
855870 *
856871 * @param {number } [delay=0] - The time to wait before invoking the complete callback. If zero it will fire immediately.
872+ *
873+ * @return {this } This Tween instance.
857874 */
858875 complete : function ( delay )
859876 {
@@ -877,6 +894,8 @@ var Tween = new Class({
877894
878895 this . state = TWEEN_CONST . PENDING_REMOVE ;
879896 }
897+
898+ return this ;
880899 } ,
881900
882901 /**
@@ -886,6 +905,8 @@ var Tween = new Class({
886905 * @since 3.0.0
887906 *
888907 * @param {number } [resetTo] - A value between 0 and 1.
908+ *
909+ * @return {this } This Tween instance.
889910 */
890911 stop : function ( resetTo )
891912 {
@@ -907,10 +928,12 @@ var Tween = new Class({
907928
908929 this . state = TWEEN_CONST . PENDING_REMOVE ;
909930 }
931+
932+ return this ;
910933 } ,
911934
912935 /**
913- * [description]
936+ * Internal method that advances the Tween based on the time values.
914937 *
915938 * @method Phaser.Tweens.Tween#update
916939 * @since 3.0.0
@@ -1016,14 +1039,14 @@ var Tween = new Class({
10161039 } ,
10171040
10181041 /**
1019- * [description]
1042+ * Internal method used as part of the playback process that sets a tween to play in reverse.
10201043 *
10211044 * @method Phaser.Tweens.Tween#setStateFromEnd
10221045 * @since 3.0.0
10231046 *
1024- * @param {Phaser.Tweens.Tween } tween - [description]
1025- * @param {Phaser.Tweens.TweenDataConfig } tweenData - [description]
1026- * @param {number } diff - [description]
1047+ * @param {Phaser.Tweens.Tween } tween - The Tween to update.
1048+ * @param {Phaser.Tweens.TweenDataConfig } tweenData - The TweenData property to update.
1049+ * @param {number } diff - Any extra time that needs to be accounted for in the elapsed and progress values.
10271050 *
10281051 * @return {integer } The state of this Tween.
10291052 */
@@ -1120,14 +1143,14 @@ var Tween = new Class({
11201143 } ,
11211144
11221145 /**
1123- * Was PLAYING_BACKWARD and has hit the start.
1146+ * Internal method used as part of the playback process that sets a tween to play from the start.
11241147 *
11251148 * @method Phaser.Tweens.Tween#setStateFromStart
11261149 * @since 3.0.0
11271150 *
1128- * @param {Phaser.Tweens.Tween } tween - [description]
1129- * @param {Phaser.Tweens.TweenDataConfig } tweenData - A TweenData object contains all the information related to a tween. Created by and belongs to a Phaser.Tween object .
1130- * @param {number } diff - [description]
1151+ * @param {Phaser.Tweens.Tween } tween - The Tween to update.
1152+ * @param {Phaser.Tweens.TweenDataConfig } tweenData - The TweenData property to update .
1153+ * @param {number } diff - Any extra time that needs to be accounted for in the elapsed and progress values.
11311154 *
11321155 * @return {integer } The state of this Tween.
11331156 */
@@ -1184,13 +1207,13 @@ var Tween = new Class({
11841207 } ,
11851208
11861209 /**
1187- * [description]
1210+ * Internal method that advances the TweenData based on the time value given.
11881211 *
11891212 * @method Phaser.Tweens.Tween#updateTweenData
11901213 * @since 3.0.0
11911214 *
1192- * @param {Phaser.Tweens.Tween } tween - [description]
1193- * @param {Phaser.Tweens.TweenDataConfig } tweenData - [description]
1215+ * @param {Phaser.Tweens.Tween } tween - The Tween to update.
1216+ * @param {Phaser.Tweens.TweenDataConfig } tweenData - The TweenData property to update.
11941217 * @param {number } delta - Either a value in ms, or 1 if Tween.useFrames is true
11951218 *
11961219 * @return {boolean } [description]
0 commit comments