AS3是否可以复制一个图形对象? [英] AS3 Is it possible to duplicate a Shape object?

查看:170
本文介绍了AS3是否可以复制一个图形对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个形状可供复制。这里是我做了什么解释,我想要做的,在这里我卡:

I'm trying to make a shape available for duplicating. Here's an explanation of what I've done, what I'm trying to do, and where I'm stuck:

  • 在画了手动在Flash IDE(画笔)的形状
  • 创建一个包含形状的新影片剪辑;出口为一类。
  • 类实例。(VAR MC:影片剪辑=新shapeMovieClip())<​​/ li>
  • 添加引用形状的 MC 的,我想(MyShape的变种:形状= mc.getChildAt(0)为形状;
  • 这完美的作品,我现在有我的造型,但我怎么能复制它没有实例父MovieClip类 - ?是否有可能
  • Drew a shape manually in the Flash IDE (paintbrush).
  • Created a new movieclip containing the shape; exports as a class.
  • Instantiate the class (var mc:MovieClip = new shapeMovieClip()).
  • Add a reference to the shape in mc that I want (var myShape:Shape = mc.getChildAt(0) as Shape;
  • This works perfect and I now have my shape, but how can I duplicate it without instantiating the parent MovieClip class - is it possible?

我试图创建一个新的形状,并使用具有copyfrom()图形方法都无济于事,我相信这个方法只是复制画时,他们对所引用的图形的调用,而是我只是有一个形状的参考这已经被画。

I've tried creating a new shape and using the copyFrom() graphics method with no avail, I believe this method just copies draw calls when they're made on the referenced graphics and instead I just have a reference of a shape that's already been drawn.

现在,我延长了影片剪辑作为一个精灵,而不是实例化,从父拉形状和保存其引用,然后调零的精灵。有谁知道一个更好,更轻便,战略,以这种方式复制形状?

Right now I'm extending the movieclip as a sprite instead, instantiating, pulling the shape from the parent and saving its reference, and then nulling the sprite. Does anyone know of a better, more lightweight, strategy for duplicating Shapes in this manner?

推荐答案

基本上取决于你是否需要扩展的形状。如果不这样做,你可以解决它与一个固定大小的位图重$ P $形状psentation,那么你将得到更好的性能你的形状绘制为BitmapData(这就是所谓的光栅化)和instanciating位图对象(如其他评论者所指出的那样)。在code会去是这样的:

Basically depends on whether you need to scale your shapes. If you don't, and you can work it out with a fixed sized bitmap representation of the shape, then you will get much better performance drawing your shape to a BitmapData (it's called rasterisation) and instanciating Bitmap objects (as other commenters have pointed out). The code would go something like this:

var base:Sprite = new shapeMovieClip();
var bmd:BitmapData = new BitmapData(base.width, base.height, true, 0);
bmd.draw(base);
var clip1:Bitmap = new Bitmap(bmd);
var clip2:Bitmap = new Bitmap(bmd);

如果您确实需要扩展剪辑,你会得到使用像素化的位图。当缩小将Bitmap.smoothi​​ng有助于在一定程度上(也转动时),但如果你需要扩大规模,你可能会使用某种的 MIP映射。这基本上是建立在不同等级水平的形状的几个位图,然后交换它们根据当前的规模​​。编码此有一定的复杂性(使用帮助家长调整尺寸可以帮助),但它肯定会执行比使用许多形状符号(有或没有精灵父母)更好。

If you do need to scale the clips, you will get pixelation using bitmaps. When scaling down Bitmap.smoothing can help to some extent (also when rotating), but if you need to scale up, you will probably have to use some kind of mip-mapping. This is basically creating a few bitmaps of the shape at different scale levels, and then swap them depending on the current scale. Coding this has some complexity (using a helper parent to adjust the scale can help) but it will definitely perform better than using many shape symbols (with or without a sprite parent).

这篇关于AS3是否可以复制一个图形对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆