在 EaselJS 中将矢量绘制到位图

发布于 2024-11-05 08:17:19 字数 202 浏览 0 评论 0原文

我正在开发一个 EaselJS 程序,该程序不断绘制数千个向量。不用说,短时间后,性能就会下降。为了在 Flash 中解决这个问题,我会在矢量后面创建一个位图,并定期将矢量绘制到该位图上,并将它们从显示列表中删除。

我在 EaselJS 中执行此操作时遇到困难,即使看起来所有部分都已就位。如何创建一个空的 Bitmap() 并将 Container() 的内容绘制到其中?

I'm working on an EaselJS program that continually draws thousands of vectors. Needless to say, after a short amount of time, performance drops. To solve this in Flash, I would have created a Bitmap behind the vectors and periodically draw the vectors to that Bitmap and remove them from the display list.

I'm having trouble doing this in EaselJS, even though it seems like all the pieces are in place. How can I create an empty Bitmap() and draw the contents of my Container() to it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戒ㄋ 2024-11-12 08:17:19

我认为你可以将所有内容放入容器中并缓存它。

var vectorContainer=new Container;
for (var i = 0;i<numVectors;i++){
  var vector=new Shape();
  //draw whatever vector you want to vector.graphics
  vectorContainer.addChild(vector);
}
vectorContainer.cache(someX,someY,someW,someH);

但是,请获取最新的未标记版本,因为当前版本存在错误并且无法正确缓存容器。

I think you can just put everything in a container and cache it.

var vectorContainer=new Container;
for (var i = 0;i<numVectors;i++){
  var vector=new Shape();
  //draw whatever vector you want to vector.graphics
  vectorContainer.addChild(vector);
}
vectorContainer.cache(someX,someY,someW,someH);

However get the newest untagged build as the current release has a bug and doesn't cache container properly.

梦亿 2024-11-12 08:17:19

我还向向量添加了“snapToPixel = true”,因为我读到它应该在某些浏览器中有所帮助。因此,在上面的示例代码中,我将在进行缓存的最后一行之前添加以下行。

vectorContainer.snapToPixel = true;

请查看缓存和对齐像素设置演示来了解一个活生生的例子。

在我设置的特定浏览器中,捕捉到像素实际上并不会改变性能,但在我阅读文档时,它似乎应该改变。

I've also been adding the 'snapToPixel = true' to vectors because I've read it is supposed to help in some browsers. So, in your example code above, I would add the following line right before the last line where you do your caching.

vectorContainer.snapToPixel = true;

Check out this demo of cache and snap to pixel settings to see a live example.

In my particular browser set up, the snap to pixel does not actually change the performance, but in my reading of the docs it seems like it should.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文