Neato - my first carousel is now live and what have I learned? Well there's a ton of great examples of carousels around - that's the first thing. The second? Always check if something is in AS2 before you try to compile it in AS3. Duh. Now for my own meager contribution: intervals. I had my fancy carousel flying around and I wanted to slow down each item as it arrived at the front. Sounds easy? Sure, but I'm no maths wiz so it took me a while to pen, paper and scratch forehead on this one. Here's the final idea I came up with:
- A function which ascertains how big the remainder of a division is
- An arbitrary increment based on circumference divided by the number of objects
- Testing the function on the position around the circumference divided by _2_ above
- Slowing the shifted increment of the carousel as a result of a true return from the function
Here's the code:
// if ((shift / intIncrement) == round number) { shift = an interval }
// and shift by a smaller increment as a result
function isCloseToRound(num:Number):Boolean {
if (( num%1 ) < 0.1 ) {
return true;
}
else {
return false;
}
}
var intIncrement = (( Math.PI*2 ) / numObj );
if (isCloseToRound(shift / intIncrement)) {
shift += shiftIncrement / 2;
}
else
{
shift += shiftIncrement; // 0.02 at start
}
No comments:
Post a Comment