A Flash Developer Resource Site

Thread: Pushing A Cart Graphic By Its Handle, Rotating In Its Midsection?

1. Pushing A Cart Graphic By Its Handle, Rotating In Its Midsection?

Hello,
I have a cart graphic, which has wheels in its mid-section. Please see my example so far, which works correctly:
http://www.avtutorials.com/temp/test...rotate_5a.html

I need to push the cart by its handle, so that it rotates along the wheels at the midsection -- to do so, drag the blue "target," and the cart will follow or push appropriately.

My problem is this: the cart graphic is currently centered over its registration point in its Movie Clip container (x= -61.5, y= -100.5) -- that's the only way I've been able to get this to work. However, I need to put the cart graphic at the 0,0 point. By positioning the graphic at 0,0 in its Movie Clip, this "offsets" it, and my math doesn't work.

I cannot seem to write the math properly to adjust for this "offset."

Below is my code. Could anyone help determine what I need to change in my code, if I am to have the graphic positioned at 0,0 in its Movie Clip instead of being centered on the registration point?

Code:
```towTarget.addEventListener(MouseEvent.MOUSE_DOWN, startMove);

var cartHeight:Number = cart.height;

var myAtan2:Number;
var movementInProgress:Boolean = false;

function startMove(evt:MouseEvent):void {
movementInProgress = true;
evt.target.startDrag();

}

function stopMove(evt:MouseEvent):void {
movementInProgress = false;
stopDrag();

myAtan2 = Math.atan2(towTarget.y - cart.y, towTarget.x - cart.x);
cart.x = towTarget.x - Math.cos(myAtan2) * (cartHeight/2);
cart.y = towTarget.y - Math.sin(myAtan2) * (cartHeight/2);

removeEventListener(MouseEvent.MOUSE_MOVE, checkMouse);
}

function checkMouse(evt:Event ):void {
if (movementInProgress == true) {
myAtan2 = Math.atan2(towTarget.y - cart.y, towTarget.x - cart.x);
cart.x = towTarget.x - Math.cos(myAtan2) * (cartHeight/2);
cart.y = towTarget.y - Math.sin(myAtan2) * (cartHeight/2);

cart.rotation = (myAtan2 * 180 / Math.PI) + 90;
}
}```

2. I solved it. Thanks to everyone who took a look through this.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap