Pivot Rotate Example

Tagged:  

PivotRotate.as allows you to rotate around a pivot point in flash instead of just the 0, 0 point.

Usage example:

	var pivotPoint:Point = new Point(30, 20);
	var pivotRotate:PivotRotate = new PivotRotate(shape1_mc, pivotPoint);
	pivotRotate.rotation = 90;

The reason behind having a PivotRotate Object being instantiated is so that you can use Tweener to target pivotRotate.rotation.

Directions: Click somewhere on the shape to set the pivot point, then drag the mouse to rotate around that point.

This site requires the Flash player to display correctly. Go to http://www.adobe.com/go/getflash/ to download this plugin.

AttachmentSize
pivotRotateExample.zip11.29 KB
pivotRotateSrc.zip13.14 KB
pivotRotateExample2.zip12.71 KB


var pivotPoint:Point = new Point(30, 20);
var pivotRotate:PivotRotate = new PivotRotate(shape1_mc, pivotPoint);
pivotRotate.rotation = 90;

pivotRotate isn't found if I use this. Later it calls an undefined method.
Any ideas?

Try the example .zip

I realized that example 1, even though it shows what you can do with PivotRotate, it isn't the most practical of situations. As Matt said, he wants to be able to set a pivot point on a movieclip and have that be basically its new registration point.
This is how I typically use this class as well.

Example 2 shows you how to do that.

In Example 2, we have PivotShape, which is an extension of MovieClip. PivotShape implements IPivotable, which has the getters/setters:

function get pivotPoint():Point;
function set pivotPoint(value:Point):void;
function get rotation2():Number; 
function set rotation2(value:Number):void;

So if you have a MovieClip that is a PivotShape, you can set rotation2 instead of rotation, which will pivot around pivotPoint instead of 0,0.

Try out the example and let me know if it's intuitive enough.

Thank you for the example, I have been trying to figure out how to rotate around a pivot point and your example helped greatly, though I can't figure out how to set a permanent pivot point, since your example allows to set the pivot point on click and what I need to do is have a set point and allow the user to rotate an object around the pivot point by clicking on it and dragging.

Any suggestions?

Again, keep up the great work as I find all your examples very useful.

Matt

Sorry this wasn't working earlier, I'm adding a preloader to all swfs on the site, and that caused some things to break.