Return to Snippet

Revision: 65850
at January 29, 2014 08:31 by ACodeGerm


Initial Code
//TODOWish I had more time to clean this up!
		//The delay count ends up here. The actual handles rotation itself is based off
		//of this number. The amount we rotate the handle = Max delay - current delay. 
		public static var hardCodedDelay:Number = 0.3800000000000001;
		public var delayCount:Number = hardCodedDelay;
		
		//Arbitrary minimum amount of delay, before it looked like it was moving too fast.
		public var delayCountMin:Number = .03;
		
		//Seemed like a good value for speed up and slow down. Not too abrupt, eyeballed this. Arbitrary.
		public var delayChange:Number = .035;
		
		public var curIndex:int;
		
		public var spinIndexCount:int;
		public var curSpinPos:int = 0;
		
		public function Spin():void
		{	
			//Returns the index of the sceneobject's layer.
			//We cycle through each of the layers (ordered in a clockwise fashion.
			
			//So, get the current target, and move the target index forward.
			var targetPos:int =
				ReturnTargetPosition(spinTargets[spinTargetIndex++].target);
			
			//how far off are we currently from the target position.
			var posDifference:int = targetPos - curSpinPos;
			//How many times we want to go around the frame.
			var spinsAroundFrameCount:int = 2;
			
			//Start the delay count low.
			delayCount = .15;
			wheelState = WHEEL_START;
			
			//This many indices until we reach our target.
			spinIndexCount = spinsAroundFrameCount * vaultIndicesArr.length + posDifference;
			
			SpinNextIndex();
		}
		
		public function SpinNextIndex():void
		{
			var curSpinPosNum:DI_V_VaultFrame_Number = vaultIndicesArr[curSpinPos];

			//Less than eleven(arbitrary) targets, slow down.
			if(spinIndexCount < 10)
			{
				wheelState = WHEEL_SLOW;
			}
			
			//Call to a function that tweens the current icon's from its selected colour,
			//back to its resting state.
			curSpinPosNum.TriggerRollover();
			
			//If we have just spun, we set the state to WHEEL_START
			if(wheelState == WHEEL_START)
			{
				delayCount -= delayChange;
				
				if(delayCount < delayCountMin)
				{
					delayCount = delayCountMin;
					
					wheelState = WHEEL_SPIN;
				}
			}
			//Slowing down, add to delay.
			else if(wheelState == WHEEL_SLOW)
			{
				delayCount += delayChange;
			}
			
			//Lets advance the spin pos for the next time this function is called.
			if(++curSpinPos == vaultIndicesArr.length) {curSpinPos = 0;}
			
			//Reduce the spin index count, check if we have hit zero yet.
			if(spinIndexCount-- > 0)
			{
				//If we haven't cue up our next spin with its modified delayCount.
				TweenMax.delayedCall(delayCount, SpinNextIndex);
			}
			else
			{
				//OTherwise, we're done, lets pass the current VaultFrame_Number to handle being landed on. 
				TweenMax.delayedCall(.5, LandedOnIndex, [curSpinPosNum]);
			}
		}

Initial URL


Initial Description
Quick snippet for Aaron

Initial Title
Vault Number Spin

Initial Tags


Initial Language
ActionScript 3