闪存性能的游戏开发:原生渲染VS的BitmapData帧缓冲 [英] Flash performance for game dev: native render VS BitmapData framebuffer

查看:145
本文介绍了闪存性能的游戏开发:原生渲染VS的BitmapData帧缓冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个2D射击游戏的大量的对象侵略性滚动的。

I develop a 2D shooter game with lots of objects and aggressive scrolling.

问:哪种方式比较好

选择1 - 使用本机Flash渲染:

CHOICE 1 - use native Flash rendering:

  • 来源于位图的游戏对象,利用现有的x,y,宽度,高度,位图数据
  • 添加所有对象为儿童UIComponent.addChild(...),以sccreen
  • 在使用scrollRect的片段可见区域

选择2 - 编写使用位图+ copyPixels自定义渲染

CHOICE 2 - write custom rendering using "bitmap + copyPixels"

  • 使用自己的游戏对象的x,y,宽度,高度,位图数据
  • 添加一个位图到屏幕上,获取BitmapData从它
  • 在重绘每个ENTER_FRAME:bitmapData.lock(),遍历游戏对象和copyPixels()成位图数据,然后bitmapData.unlock()
  • 在自定义的剪辑:不呈现出的画面对象的

在这里,在这个问题的一些人抱怨说:位图+ copyPixels()是缓慢的。

Here in this question some people complain that "bitmap + copyPixels()" is slow.

实验:我已经实现了这两种技术:

EXPERIMENT: I have implemented both techniques:

  • <一个href="http://sites.google.com/site/oshyshko/framebuffer%5Fvs%5Fnativerender/main%5F1%5Fmore%5Fcreeps.swf?attredirects=0">main_1.swf - 本地
  • <一个href="http://sites.google.com/site/oshyshko/framebuffer%5Fvs%5Fnativerender/main%5F2%5Fmore%5Fcreeps.swf?attredirects=0">main_2.swf - 自定义的
  • main_1.swf - native
  • main_2.swf - custom

请,试戴并分辨出哪个是更好的(更快,更流畅,吃更少的CPU)。

Please, try them and tell which one is better (faster, smoother, eats less CPU).

等到会出现的至少250个敌人的(计数器屏幕上方)。
更新:尝试打开任务管理器(或$顶部),看看整体的CPU使用率

Wait until there will be at least 250 enemies (counter above the screen).
UPDATE: Try to open Task Manager (or $top) and see overall CPU usage

更新2:我已经改变了code,现在悄悄产卵更快

UPDATE 2: I've changed the code, now creeps spawn much faster.

推荐答案

更​​新:感谢您的高压力的版本。同样,我也实在看不出差别只是跑来跑去。但是,我巧妙地想通了,R滴炮塔,当我放弃了20-30炮塔,本机版本比说明书一本有点慢,所以也许我错了。 (我看到的内存使用情况无差异。)它似乎仍然喜欢做的事情本身应该有更快的潜力,但它可能是,这将需要一些不透明的某种专门的处理。

Update: thanks for the high-stress version. Again, I couldn't really see a difference just running around. But I cleverly figured out that "r" drops turrets, and when I dropped 20-30 turrets, the native version was somewhat slower than the manual one, so maybe I was wrong. (I saw no difference in memory usage.) It still seems like doing things natively ought to have the potential to be faster, but it may well be that it would require specialized handling of some opaque sort.

由于这个被接受,我会添加注释作出明确我在一个注释不同的回答说:如果你的资产是位图本身,那么作为HanClinto指出,这并不奇怪地发现,人工合成它们可以是不是让本机对象,让闪存做的工作速度更快,因为它消除了与显示对象关联的,就像事件结构的开销。

Since this was accepted I'll add a note to make explicit what I said in a comment to a different answer: If all your assets are bitmaps themselves, then as HanClinto points out it's not surprising to find that compositing them manually can be faster than making native objects and letting Flash do the work, since it eliminates the overhead associated with display objects, like event structures.

不过也有可能的情况下做的事情手工可能会胜出,比如,如果你有需要被渲染成位图矢量的内容,或大量动画精灵的,或者如果你需要检测你的角色鼠标事件(其中你需要做手工,也许是痛苦的,如果你做你自己的合成)。

However there are probably situations where doing things manually might win out, such as if you have vector contents that need to be rendered into bitmaps, or lots of animated sprites, or if you need to detect mouse events on your actors (which you'd need to do manually, perhaps painfully, if you do your own compositing).

所以,如果你不需要做任何事情,会减慢人工合成,它似乎确实是最好的答案,如果你这样做,那么尝试这两种方法是绝对肯定的最佳方式。 (混合模式也有可能,你做一个层需要鼠标事件本机对象,并覆盖或一层人工合成位图下垫了。)

So if you don't need to do anything that would slow down manual compositing, it appears to definitely be the best answer, and if you do, then trying both approaches is the best way to be absolutely sure. (A hybrid model is also possible, where you make one layer of native objects that need mouse events, and overlay or underlay it with a layer of manually composited bitmaps.)

这篇关于闪存性能的游戏开发:原生渲染VS的BitmapData帧缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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