简体   繁体   中英

Object does not rotate around pivot point

I have an object which looks like this: 在此输入图像描述

When I try to rotate it using [INSTANCENAME].rotation += 10; it still rotates around the middle of the object. Am I doing something wrong?

I've done a little research, and apparently there is no direct way to change the pivot point programmatically, AFAIK. Rather odd, seeing as you can change it in the Flash Pro IDE. (For those reading, the pivot point is NOT the same as the registration point.)

[EDIT: Thinking more about it, I don't think the pivot point actually "exists", at least in the context of a programmable property. It only exists in the context of some tools in the Flash IDE.]

You will need to place your object ALONE inside another object, so that the desired pivot point of the inner object is over the center of the outer object. Then, rotate the outer object.

You can later control your object's "pivot point" by changing the position of the inner object.

Since the outer object's center moves depending on its size, and the position of the inner object determines the size of the outer object, you'd need to apply some math. The x position of the inner object would need to be equal to the distance from the desired pivot point on the inner object to the far right edge of that inner object. The same concept applies to the y position.

This can be accomplished both in the IDE directly, or through code, whichever you choose.

An example of code to change this dynamically. This function is inside the outer object. (You can get pivotX and pivotY off an event listener, if you want.) [Sorry, the code is untested.]

function newPivot(int pivotX, int pivotY):void
{
   inner.x = inner.width - pivotX;
   inner.y = inner.height - pivotY;
}

I hope that solves your problem!

A very simple way is to do like this.

  1. Convert the image to a symbol(MovieClip). [you might have already done it].
  2. Double Click on the MovieClip/Sprite to enter inside.
  3. Move the Image so that the registration point align towards the pivot.

NB: Applicable only in case of FLASH IDE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM