开发者

AS3 Change registration point of a MovieClip to be center of width and bottom

I have a MC in an AS3 animation and I want to increase its height from bottom to top which would mean that the registration point should be bottom of the MC and center of width (hori开发者_开发技巧zontal center).

How can I do this please?

Thank you.


ah, the old registration point problem. :)

i once saw a small custom class that allowed you to change the registration point of your display object, as you can simply do in Flash Authoring. google around if you're curious.

the solution is rather easy, though. the registration point of display objects is assigned based on how the object is added to the display list. you just have to take that into account when your are adding the display object to the display list, then set up a bit of easy math to change the registration point:

//Set up rect's width and height
var rectWidth:uint = 200;
var rectHeight:uint = 100;

//Assign registration point (TL, TC, TR, CL, C, CR, BL, BC, BR = top, center, bottom, left, right)
var registration:String = "C"

//Assign rect's X and Y properties
var rectX:int;
var rectY:int;

switch (registration)
       {
       case "TL": rectX = 0;
                  rectY = 0;
                  break;

       case "TC": rectX = -rectWidth / 2;
                  rectY = 0;
                  break;

       case "TR": rectX = -rectWidth;
                  rectY = 0;
                  break;

       case "CL": rectX = 0;
                  rectY = -rectHeight / 2;
                  break;

       case "C":  rectX = -rectWidth / 2;
                  rectY = -rectHeight / 2;
                  break;

       case "CR": rectX = -rectWidth;
                  rectY = -rectHeight / 2;
                  break;

       case "BL": rectX = 0;
                  rectY = -rectHeight;
                  break;

       case "BC": rectX = -rectWidth / 2;
                  rectY = -rectHeight;
                  break;

       case "BR": rectX = -rectWidth;
                  rectY = -rectHeight;
       }


//Draw the rect
var rect:Sprite = new Sprite();
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(rectX, rectY, rectWidth, rectHeight);
rect.graphics.endFill();


My recommendation to the old registration point problem, few things...

  • If you can edit the symbol and you only have a few to process, honestly - do it manually.
  • If you have quite a handful to process but still could hire monkeys to re-position the symbols, consider looking into JSFL scripts to batch process your selection of Library symbols.
  • If you MUST use AS3 to dynamically reposition it...

    • And you don't mind putting the object into another container, put it into a new Sprite object at a location where its bottom center meets the (0,0) location, then you can scale the sprite container instead of your asset.
    • And you don't mind sacrificing vector quality for a BitmapData snapshot of your asset, take a snapshot of your asset (as it would appear "fully opened / stretched), crop the bitmap (by using a combination of:

    var rect:Rectangle = bitmapData.getColorBoundsRect(0xff000000, 0, false); yourCroppedBitmapData.copyPixels( bitmapData, rect, ... );

    ... once you have a reliable top-left cornered registration point, you can do the math to position this Bitmap in a Sprite container (as above) to scale it upwards.

Or... hiring monkeys would be fun too :P

But yeah, those are some of the alternate ways you can reposition the symbols.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜