开发者

Draw a rectangle using the graphics class, but move the registration point

开发者 https://www.devze.com 2023-03-06 15:44 出处:网络
I have the following code to create a Sprite with a rectangle in it: container = new Sprite(); containe开发者_如何学Cr.graphics.beginFill(0x00CCFF, .5);

I have the following code to create a Sprite with a rectangle in it:

container = new Sprite();
containe开发者_如何学Cr.graphics.beginFill(0x00CCFF, .5);
container.graphics.lineStyle(1, 0x00CCFF);
container.graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
container.graphics.endFill()
addChild(container);

The only thing is, I'd like the registration point to be in the middle (not the top left corner). Is there a way to set up the registration point in the middle of the rectangle, but still have the position of the rectangle be correct?

i.e. not moved over so that the top left corner of the rectangle is in the "middle" of where I want the rectangle to be...


The closest you can do is:

container.graphics.drawRect(rect.x-rect.width/2, rect.y-rect.height/2, rect.width, rect.height);

But I think that is what you are saying you don't want to do. Although, there might be a way it can be done with a Matrix.

Edit:

It looks like this other StackOverflow post might have some more answers for you regarding using a transform matrix, and a few other possibilities.

0

精彩评论

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

关注公众号