简体   繁体   English

在Actionscript中绘制形状

[英]Drawing shapes in Actionscript

So I need to draw some custom shapes in Actionscript on canvas dynamically(like some spinning wheel made of lines and circles). 因此,我需要动态地在画布上的Actionscript中绘制一些自定义形状(就像一些由线条和圆圈组成的旋转轮)。 I'm using Flash Builder. 我正在使用Flash Builder。

Question 1: What would work better(faster): 问题1:什么会更好(更快):

  • Draw on graphics of canvas, on each frame clean everything and redraw? 在画布上绘制图形,在每个框架上清理所有内容并重绘?
  • Create multiple Shape objects and transform them correspondingly? 创建多个Shape对象并相应地转换它们?

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). 问题2:如何相对于其中心旋转一些Shape,而不是相对于其父元素?(尝试使用矩阵但它们相对于父容器工作)。 Maybe there is some push pop matrix functionality? 也许有一些推流行矩阵功能?

Question 1: Almost certainly using the Shapes directly will be faster. 问题1:几乎可以肯定直接使用Shapes会更快。 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. 当不是必须重新绘制所有内容时,Flash Player将更好地更新屏幕等。但是,当性能是一个问题时,通常最好编写一个简短的测试。

Question 2: Shapes are DisplayObjects , so you can just use the rotation property, and they will rotate about their origin (the (0,0) point). 问题2: ShapesDisplayObjects ,因此您可以只使用rotation属性,它们将围绕它们的原点( (0,0)点)旋转。 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)): 只需确保相对于原点绘制形状,并使用其x y属性将其移动到正确的位置(例如,对于以(70,70)为中心的20x20矩形):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM