0
votes

So I need to draw some custom shapes in Actionscript on canvas dynamically(like some spinning wheel made of lines and circles). I'm using Flash Builder.

Question 1: What would work better(faster):

  • Draw on graphics of canvas, on each frame clean everything and redraw?
  • Create multiple Shape objects and transform them correspondingly?

Question 2: How can I spin some Shape relatively to its center, but not relatively to its parent?(Tried playing with matrices but they work relatively to parent container). Maybe there is some push pop matrix functionality?

1

1 Answers

2
votes

Question 1: Almost certainly using the Shapes directly will be faster. Flash Player will do a better job of updating the screen when not everything has to be redrawn, etc. However, it is usually better to write a short test when performance is a question.

Question 2: Shapes are DisplayObjects, so you can just use the rotation property, and they will rotate about their origin (the (0,0) point). Just make sure that you draw your shape relative to the origin, and move it to the right place using its x y properties (for example, for a 20x20 rectangle centered at (70,70)):

var rect : Shape = new Shape();
rect.graphics.beginFill(0xffffff);
rect.graphics.drawRect(-10,-10,20,20); // center it properly about (0,0)
rect.graphics.endFill();
rect.x = 70.0; rect.y = 70.0; rect.rotation = 45.0; // move and rotate