我已经在 Flash 游戏上工作了一个月,该游戏应该可以在浏览器中玩(轻计算)。话虽这么说,我注意到在某些浏览器中游戏的运行速度看起来像是 15 fps(游戏应该以 80 fps 运行)。众所周知,这种情况在 IE9 中会发生,快速修复方法是将这一行添加到 html 的顶部:
<meta http-equiv="X-UA-Compatible" value="IE=9">
这是一个快速修复方法,强制 IE 进入兼容模式并大大提高了 fps(到大约... 60,这么说吧)。
尽管如此,我相信游戏在每个浏览器中的运行速度都比应有的要慢,这一点在将 html 版本与 swf 进行比较时显而易见。
游戏 (html) 中的运动“倾斜”也是相当明显的:这些倾斜损害了游戏的美感,从而损害了可玩性!
所有这些让我相信浏览器限制了对计算机显卡的访问;
1) html 很慢,swf 很快
2) 声音以正常速度播放,但图形滞后
编辑
3) 游戏中的所有图形分辨率都相当低(即游戏中显示的图形)因为 width1xheight1 是 width1xheight1 png 的动画片段)+尽可能小
4)我制作了非常(计算上)简单的 Flash 项目,并看到了相同的图形移动问题。
谁能给我一些关于如何提高浏览器中游戏流畅度的建议?
I've been working for a month on a flash game, which should be manageable to play in a browser (light computation). This being said, I've noticed that in some browsers the game runs at what looks like 15 fps (the game should run in 80fps). This has been known to happen in IE9, and the quick fix was to add this line to the top of the html:
<meta http-equiv="X-UA-Compatible" value="IE=9">
This was a quick-fix that forces IE into compatibility mode and greatly improved the fps (to about... 60, let's say).
Still, I believe that the game is running slower than it should in every browser, which is evident when the html version is compared to the swf.
It's also fairly noticeable that the movement in the game (html) "lurches": these lurches injure the aesthetics of the game, and therefore the playability!
All of this leads me to believe that browsers limit access to computers' graphics card;
1) It's slow in html, and fast in swf
2) Sounds play at normal speed, yet graphics lag
EDIT
3) All the graphics in the game are fairly low resolution (i.e., graphics that are displayed ingame as width1xheight1 are movieclips of width1xheight1 png's) + as minimal as possible
4) I've made very (computationally) simple flash projects and seen the same graphic-movement problems.
Can anyone give me some advice as to how I can increase the smoothness of my game in browsers?
发布评论
评论(1)
这可能是 SWF 如何嵌入 HTML 页面的症状。 Flash 支持多种“窗口模式”,这些模式决定了内容如何呈现到浏览器窗口中。当 SWF 嵌入到 HTML 页面中时,这是通过
wmode
参数设置的。根据 Adobe 文档,应将其设置为“direct”以获得最佳性能:
实际上,
wmode
的行为可能不稳定,因此尝试 文档。其他可能有助于提高性能的选项包括:
stage.scaleMode = StageScaleMode.NO_SCALE
。如果嵌入的尺寸与原始尺寸不匹配,这将防止内容被缩放。缩放会增加 CPU 使用率,因此禁用它会增加帧速率(请参阅 StageScaleMode#NO_SCALE)。opaqueBackground
。透明度需要额外的计算来将前景色与背景色相乘。设置不透明背景会绕过这些额外的计算,并可能会导致性能提升。 (请参阅 DisplayObject#opaqueBackground )This could be a symptom of how the SWF is embedded in the HTML page. Flash supports a number of "window modes" which determine how the content is rendered into the browser window. This is set via the
wmode
parameter when the SWF is embedded in the HTML page.According to Adobe's documentation, this should be set to "direct" for best performance:
In practice, the
wmode
can act erratically so it may help to try the alternatives mentioned in the documentation.Other options which may help improve performance are:
stage.scaleMode = StageScaleMode.NO_SCALE
. This will prevent content from being scaled should the embedded size not match the original size. Scaling contributes to CPU usage so disabling it should increase the frame-rate (see StageScaleMode#NO_SCALE).opaqueBackground
on non-transparent MovieClips (such as the root MovieClip). Transparency requires extra calculations to multiply the foreground color with the background color. Setting an opaque background bypasses these additional calculations and may result in a performance boost. (see DisplayObject#opaqueBackground)