What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »
I feel like a dumb dumb having problems with this, and probably just need a pair of fresh eyes. My problem is simple:
Rotation in AS3 goes as -180 to +180, and I want to find the difference between two rotations. So finding it – only having one direction in mind is simple, but if I want to take the other direction in regards, it get slightly more tricky.
You could imagine a situation in which you have a pool of objects (call them rotators), half of which always rotate clockwise and the other half always rotate counter-clockwise so that, over time, the rotation value of these objects tends to either +infinity or -infinity. Further imagine that, every frame, you want to know the rotation difference between every pair of rotators. The magnitude of the difference as suggested, when taken between a clockwise rotator and a counter-clockwise rotator can be, after enough time has elapsed, arbitrarily large, leading to one of the while loops needing an arbitrarily large number of passes to compute a difference in the ]-180; 180] interval. This would in turn yield lag.
Instead of using while loops, you might want to simply compute the number of loops and subtract it from the value of the rotation.
difference = rotation2 - rotation1;
var loops:int = (difference + 180)/ 360;
difference -= loops * 360;
Bam! Done. No while, no lag. The final value is in the [-180; 180[ range because that’s what you wanted. If you simply wanted a value in the [0; 360[ range you’d take out the +180 in the loops formula.
~~Also, for the record, rotation in AS3 does not go as -180 to 180.~~
Edit: \/ Yea, if you’re using the .rotation property the value you set for the rotation is already converted to the [-180, 180] range, so indeed all values you would obtain for the difference should be limited to the [-360; 360] range and neither while loop can run more than once. But then there’s no reason to have two while loops where two if statements would do the job, and still no reason to have two if statements where one operation will work as well.
If I understand you correctly… I am only going to look into what direction my objects are currently pointing towards, rather than looking at how much they have rotated in total.
-180 to 180 is coming from [the rotation property](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#rotation)
You’d expect rotationDifferent%360 would work, but I’ve had some trouble with it in the past. It should be the quickest solution (what Ace said, but it does it automatically). Then, subtract 180 at the end to get in the desired range.