I am generating sprites programatically like this:
this.food = new Sprite();
this.food.graphics.beginFill(0xFFFFFF);
this.food.graphics.drawRect(0, 0, 10, 10);
this.food.filters = [new GlowFilter(0xFF6699, .80, 5, 5, 2, 2, false, false)];
this.food.graphics.endFill();
this.food.x = this.x;
this.food.y = this.y;
this.stage.addChild(this.food);
And later on I'm doing this:
public function update():void
{
// Spin the food
this.food.rotation += 1;
}
I basically want the food sprite to spin slowly about its center, not its x and y value which is the top left corner of the sprite.
How can I make the anchor the center of the sprite?
I found another approach using the Matrix Object and the transform method. Maybe it's still helpful.
http://jamesvango.co.uk/blog/?p=136
Use the first two parameters of
drawRect()
to offset the graphics:The idea is to subtract half of the
width
andheight
from thex
andy
to centre.