PDA

View Full Version : draw a shape with a registration point bottom left?



lope
September 14th, 2009, 04:11 AM
I need to have 2 kinds of masks, one with a registration point in the top left so that when I tween its height it expands downwards, and one with a registration point in the bottom left so that when I tween its height it expands upwards?

how do i do that, with code ofcourse?

i have made something but i dont know if its the right way:
(this expands downwards, but i dont know how to get it to expand upwards)


import gs.TweenLite;

var subMask:Shape = new Shape();
var gr:Graphics = subMask.graphics;

gr.beginFill(0x0000FF, .2);
gr.drawRect(0, 0, 100, 1);
gr.endFill();

addChild(subMask);

TweenLite.to(subMask, 1, { height: 100 });

IQAndreas
September 14th, 2009, 05:36 AM
Just change the code to draw the rectangle above the x axis, and it will stretch upwards. :)

import gs.TweenLite;

var subMask:Shape = new Shape();
var gr:Graphics = subMask.graphics;

gr.beginFill(0x0000FF, .2);
gr.drawRect(0, -1, 100, 1);
gr.endFill();

addChild(subMask);

TweenLite.to(subMask, 1, { height: 100 });

efos
September 14th, 2009, 11:12 AM
IqAndreas is correct.

Alternately, you can draw up from 0 with a negative height:

gr.drawRect(0, 0, 100, -1);

For the same effect.

The point to take away from this is that you aren't tweening the shape you are tweening the DisplayObject it belongs to (subMask:Sprite); thus the shape's registration point is the origin of its parent. Changing the shape's x,y move it's registration point -x,-y.

lope
September 14th, 2009, 12:23 PM
The point to take away from this is that you aren't tweening the shape you are tweening the DisplayObject it belongs to (subMask:Sprite); thus the shape's registration point is the origin of its parent. Changing the shape's x,y move it's registration point -x,-y.

subMask is a Shape, not Sprite, but you probably mean not tweening the graphics, but Shape

efos
September 14th, 2009, 01:56 PM
Oops. Yeah, that.