@@ -1662,26 +1662,19 @@ Winwheel.prototype.startAnimation = function()
16621662 // Call function to compute the animation properties.
16631663 this . computeAnimation ( ) ;
16641664
1665- //++ when have multiple wheels and an animation for one or the other is played or stopped it affects the others
1666- //++ on the screen. Is there a way to give each wheel its own instance of tweenmax not affected by the other???
1667-
16681665 // Set this global variable to this object as an external function is required to call the draw() function on the wheel
16691666 // each loop of the animation as Greensock cannot call the draw function directly on this class.
16701667 winwheelToDrawDuringAnimation = this ;
16711668
1672- // Instruct tween to call the winwheel animation loop each tick of the animation
1673- // this is required in order to re-draw the wheel and actually show the animation.
1674- TweenMax . ticker . addEventListener ( "tick" , winwheelAnimationLoop ) ;
1675-
1676- //++ How do we replay the animation without resetting the wheel, or must we reset and what is an easy way to do this.
1677- //++ perahps the wheel state before the animation is saved?
1669+ // Put together the properties of the greesock animation.
16781670 var properties = new Array ( null ) ;
16791671 properties [ this . animation . propertyName ] = this . animation . propertyValue ; // Here we set the property to be animated and its value.
16801672 properties [ 'yoyo' ] = this . animation . yoyo ; // Set others.
16811673 properties [ 'repeat' ] = this . animation . repeat ;
16821674 properties [ 'ease' ] = this . animation . easing ;
1683- properties [ 'onComplete' ] = winwheelStopAnimation ; // This is always set to function outside of this class.
1684-
1675+ properties [ 'onUpdate' ] = winwheelAnimationLoop ; // Call function to re-draw the canvas.
1676+ properties [ 'onComplete' ] = winwheelStopAnimation ; // Call function to perform actions when animation has finished.
1677+
16851678 // Do the tween animation passing the properties from the animation object as an array of key => value pairs.
16861679 // Keep reference to the tween object in the wheel as that allows pausing, resuming, and stopping while the animation is still running.
16871680 this . tween = TweenMax . to ( this , this . animation . duration , properties ) ;
@@ -1693,15 +1686,19 @@ Winwheel.prototype.startAnimation = function()
16931686// ==================================================================================================================================================
16941687Winwheel . prototype . stopAnimation = function ( canCallback )
16951688{
1696- //++ @TODO re-check if kill is the correct thing here, and if there is more than one wheel object being animated (once sort how to do that)
1697- //++ what is the effect on it?
1689+ // @TODO as part of multiwheel, need to work out how to stop the tween for a single wheel but allow others to continue.
16981690
16991691 // We can kill the animation using our tween object.
1700- winwheelToDrawDuringAnimation . tween . kill ( ) ;
1692+ if ( winwheelToDrawDuringAnimation )
1693+ {
1694+ winwheelToDrawDuringAnimation . tween . kill ( ) ;
1695+
1696+ // Call the callback function.
1697+ winwheelStopAnimation ( canCallback ) ;
1698+ }
17011699
1702- // We should still call the external function to stop the wheel being redrawn even click and also callback any function that is supposed to be .
1700+ // Ensure the winwheelToDrawDuringAnimation is set to this class .
17031701 winwheelToDrawDuringAnimation = this ;
1704- winwheelStopAnimation ( canCallback ) ;
17051702}
17061703
17071704// ==================================================================================================================================================
@@ -1797,10 +1794,10 @@ Winwheel.prototype.computeAnimation = function()
17971794 }
17981795 else
17991796 {
1800- // We need to set the internal to 360 minus what the user entered
1801- // because the wheel spins past 0 without this it would indicate the
1802- // prize on the opposite side of the wheel .
1803- this . animation . _stopAngle = ( 360 - this . animation . stopAngle ) ;
1797+ // We need to set the internal to 360 minus what the user entered because the wheel spins past 0 without
1798+ // this it would indicate the prize on the opposite side of the wheel. We aslo need to take in to account
1799+ // the pointerAngle as the stop angle needs to be relative to that .
1800+ this . animation . _stopAngle = ( 360 - this . animation . stopAngle + this . pointerAngle ) ;
18041801 }
18051802
18061803 if ( this . animation . yoyo == null )
@@ -1904,20 +1901,26 @@ Winwheel.prototype.getRandomForSegment = function(segmentNumber)
19041901 {
19051902 var startAngle = this . segments [ segmentNumber ] . startAngle ;
19061903 var endAngle = this . segments [ segmentNumber ] . endAngle ;
1907-
19081904 var range = ( endAngle - startAngle ) - 2 ;
19091905
19101906 if ( range > 0 )
19111907 {
19121908 stopAngle = ( startAngle + 1 + Math . floor ( ( Math . random ( ) * range ) ) ) ;
1909+ }
1910+ else
1911+ {
1912+ console . log ( 'Segment size is too small to safely get random angle inside it' ) ;
19131913 }
1914-
1915- //++ At 2 degrees or less the segment is too small.
1916- //++ throw some sort of error?
19171914 }
1918- //++ Error?
1915+ else
1916+ {
1917+ console . log ( 'Segment ' + segmentNumber + ' undefined' ) ;
1918+ }
1919+ }
1920+ else
1921+ {
1922+ console . log ( 'Segment number not specified' ) ;
19191923 }
1920- //++ Throw error?
19211924
19221925 return stopAngle ;
19231926}
@@ -2122,16 +2125,12 @@ function winwheelAnimationLoop()
21222125}
21232126
21242127// ====================================================================================================================
2125- // This function is called-back when the greensock animation has finished. We remove the event listener to the function
2126- // above to stop the wheel being re-drawn all the time even though it is not animating as the greensock ticker keeps going.
2128+ // This function is called-back when the greensock animation has finished.
21272129// ====================================================================================================================
21282130var winwheelToDrawDuringAnimation = null ; // This global is set by the winwheel class to the wheel object to be re-drawn.
21292131
21302132function winwheelStopAnimation ( canCallback )
2131- {
2132- // Remove the redraw from the ticker.
2133- TweenMax . ticker . removeEventListener ( "tick" , winwheelAnimationLoop ) ;
2134-
2133+ {
21352134 // When the animation is stopped if canCallback is not false then try to call the callback.
21362135 // false can be passed in to stop the after happening if the animation has been stopped before it ended normally.
21372136 if ( canCallback != false )
0 commit comments