Skip to main content
Inspiring
June 14, 2011
Question

How to make shape rotation at it's center point?

  • June 14, 2011
  • 1 reply
  • 611 views

I draw a shape,like follows:

var shape1:Shape;

shape1=draw();
addChild(shape1);

shape1.rotation=50;

private function draw():Shape{
   var shape:Shape = new Shape();
   shape.graphics.beginFill(0x00FFFF);
   shape.graphics.moveTo(200,200);
   shape.graphics.lineTo(300, 202);
   shape.graphics.lineTo(200, 204);
   shape.graphics.lineTo(100, 202);
   shape.graphics.lineTo(200, 200);
   return shape;
  }

Then I want to rotate the shape at it's center point(200,202) by using shape1.rotation=50,but I find the shape don't rotate at the the center of it's shape. How to realize the function which make shape rotate at its center point?

Thanks

This topic has been closed for replies.

1 reply

relaxatraja
Inspiring
June 14, 2011

Here is a sample to make it rotate from center:

var sprite:Sprite=new Sprite();
sprite.graphics.lineStyle(3,0x00ff00);
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(0,0);
sprite.graphics.lineTo(100,0);
sprite.graphics.lineTo(100,100);
sprite.graphics.lineTo(0,100);
sprite.graphics.lineTo(0,0);
sprite.graphics.endFill();

var mc:Sprite=new Sprite();
mc.addChild(sprite);

//This will make the sprite to center
mc.getChildAt(0).x=-(mc.getChildAt(0).width/2);
mc.getChildAt(0).y=-(mc.getChildAt(0).height/2);
addChild(mc);


mc.x=200;
mc.y=300;

//Now it rotates from the center.

mc.rotation=20;