I’m doing a simple rotation on a sprite but there’s a weird behavior where the sprite does not rotate around it’s top left. I think I’m rotating along the top left of the test class instead of the sprite child. I would like to rotate the rectangle around it’s top left corner (kinda like a clock hand). The code is pretty short so I’ll let the code + pictures explain my problem:
package
{
import flash.display.Sprite;
public class test extends Sprite
{
public function test()
{
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x000000);
mySprite.graphics.drawRect(100,100,6,120);
mySprite.graphics.endFill();
this.addChild(mySprite);
mySprite.rotation = 45;
}
}
}
Seems too simple to screw up, well here are the results. The red line is over the home key for reference. First pic I set mySprite.rotation=0 and second is the code shown above:


I’ve read a lot of stuff about rotating around a fixed point, I’ve tried doing it with movieclips instead of sprites, I even copy pasted a tutorial on rotation and nothing works. Why does this behavior happen and how can I fix it?
Edit: Thanks everyone, all your suggestions helped me out in different ways and they were all correct so +1, I’ll just choose the solution I chose to use in my code.
The sprite is rotating around it’s top-left, but you don’t have any graphics in top-left. The bar is rendered in (100, 100). Try this: