Posted By

ACodeGerm on 01/29/14

Vault Number Spin

/ Published in: ActionScript 3

Quick snippet for Aaron

1. //TODOWish I had more time to clean this up!
2. //The delay count ends up here. The actual handles rotation itself is based off
3. //of this number. The amount we rotate the handle = Max delay - current delay.
4. public static var hardCodedDelay:Number = 0.3800000000000001;
5. public var delayCount:Number = hardCodedDelay;
6.
7. //Arbitrary minimum amount of delay, before it looked like it was moving too fast.
8. public var delayCountMin:Number = .03;
9.
10. //Seemed like a good value for speed up and slow down. Not too abrupt, eyeballed this. Arbitrary.
11. public var delayChange:Number = .035;
12.
13. public var curIndex:int;
14.
15. public var spinIndexCount:int;
16. public var curSpinPos:int = 0;
17.
18. public function Spin():void
19. {
20. //Returns the index of the sceneobject's layer.
21. //We cycle through each of the layers (ordered in a clockwise fashion.
22.
23. //So, get the current target, and move the target index forward.
24. var targetPos:int =
25. ReturnTargetPosition(spinTargets[spinTargetIndex++].target);
26.
27. //how far off are we currently from the target position.
28. var posDifference:int = targetPos - curSpinPos;
29. //How many times we want to go around the frame.
30. var spinsAroundFrameCount:int = 2;
31.
32. //Start the delay count low.
33. delayCount = .15;
34. wheelState = WHEEL_START;
35.
36. //This many indices until we reach our target.
37. spinIndexCount = spinsAroundFrameCount * vaultIndicesArr.length + posDifference;
38.
39. SpinNextIndex();
40. }
41.
42. public function SpinNextIndex():void
43. {
44. var curSpinPosNum:DI_V_VaultFrame_Number = vaultIndicesArr[curSpinPos];
45.
46. //Less than eleven(arbitrary) targets, slow down.
47. if(spinIndexCount < 10)
48. {
49. wheelState = WHEEL_SLOW;
50. }
51.
52. //Call to a function that tweens the current icon's from its selected colour,
53. //back to its resting state.
54. curSpinPosNum.TriggerRollover();
55.
56. //If we have just spun, we set the state to WHEEL_START
57. if(wheelState == WHEEL_START)
58. {
59. delayCount -= delayChange;
60.
61. if(delayCount < delayCountMin)
62. {
63. delayCount = delayCountMin;
64.
65. wheelState = WHEEL_SPIN;
66. }
67. }
68. //Slowing down, add to delay.
69. else if(wheelState == WHEEL_SLOW)
70. {
71. delayCount += delayChange;
72. }
73.
74. //Lets advance the spin pos for the next time this function is called.
75. if(++curSpinPos == vaultIndicesArr.length) {curSpinPos = 0;}
76.
77. //Reduce the spin index count, check if we have hit zero yet.
78. if(spinIndexCount-- > 0)
79. {
80. //If we haven't cue up our next spin with its modified delayCount.
81. TweenMax.delayedCall(delayCount, SpinNextIndex);
82. }
83. else
84. {
85. //OTherwise, we're done, lets pass the current VaultFrame_Number to handle being landed on.
86. TweenMax.delayedCall(.5, LandedOnIndex, [curSpinPosNum]);
87. }
88. }