Flex/Flash/AS3 中的垂直同步?

发布于 2024-07-23 09:44:49 字数 797 浏览 11 评论 0原文

我正在开发一款 2D 射击游戏,屏幕上有很多移动物体(子弹等)。

我使用 BitmapData.copyPixels(...) 将整个屏幕渲染到缓冲区:BitmapData。 然后我将像素从“缓冲区”“复制”到屏幕:BitmapData。 帧率为 60。

private var bitmap:Bitmap = new Bitmap();
private var buffer:Bitmap = new Bitmap();

private function start():void {
    addChild(bitmap);
}

private function onEnterFrame():void {
    // render into "buffer"
    // copy "buffer" -> "bitmap"
}

问题是精灵正在撕裂: 精灵的某些部分发生了水平移动。

它看起来像是关闭了 VSYNC 的 PC 游戏。

有人解决这个问题了吗?

更新:问题不在于性能,而在于消除屏幕撕裂

[!]更新:我创建了另一个问题,在这里您可以尝试两种实现方式:使用Flash方式或BitmapData+copyPixels()

I work on a 2D shooter game with lots of moving objects on the screen (bullets etc).

I use BitmapData.copyPixels(...) to render entire screen to a buffer:BitmapData.
Then I "copyPixels" from "buffer" to screen:BitmapData. The framerate is 60.

private var bitmap:Bitmap = new Bitmap();
private var buffer:Bitmap = new Bitmap();

private function start():void {
    addChild(bitmap);
}

private function onEnterFrame():void {
    // render into "buffer"
    // copy "buffer" -> "bitmap"
}

The problem is that the sprites are tearing apart:
some part of a sprite got shifted horizontally.

It looks like a PC game with VSYNC turned off.

Did anyone solve this problem?

UPDATE: the question is not about performance, but about getting rid of screen tearing.

[!] UPDATE: I've created another question and here you may try both implementations: using Flash way or BitmapData+copyPixels()

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

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

发布评论

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

评论(3

凤舞天涯 2024-07-30 09:44:49

我能感受到你们的痛苦,因为我目前正在努力开发自己的游戏。 在默认设置下,无论您生成什么代码,Flash 渲染器都会产生可怕的屏幕撕裂/垂直同步问题。

这就是为什么我很高兴找到了最简单、最优雅的答案,这不是重构代码(这没有任何帮助,问题在于 Flash 播放器,而不是代码)。

只需在发布设置中启用硬​​件加速。 有两种不同的选项:

级别 1:直接; 和级别 2:GPU

请参阅官方文档了解更多相关信息:指定 SWF 文件的发布设置< /a>,然后决定哪个选项最适合您的游戏。

目标市场确实在这里发挥着重要作用,如果这对游戏玩家来说是一款严肃的游戏,则无需担心可能的性能问题,因为大多数游戏玩家都有 GPU。

本文 没有具体为我提供解决方案,但引导我走向正确的方向。 但是,如果您的游戏要在浏览器窗口中运行,您可能还必须使用相同的技术将 wmode 设置为 direct 或 gpu。

I feel your pain as I'm currently in the trenches developing my own game. At default settings, the Flash renderer produces horrible screen tearing / v-sync issues, regardless of what code you produce.

This is why I was pleased to have found the most simple, elegant answer, that wasn't re-factoring code (which doesn't help a single bit, the problem is the Flash player, not code).

Just enable Hardware Acceleration in your Publish Settings. There's two different options:

Level 1: Direct; and Level 2: GPU.

Read more about it at the official documentation: Specify publish settings for SWF files, and decide what option is best for your game.

Target market does play a factor here, if it's a serious game for gamers, you don't need to worry about possible performance issues, as most gamers have GPU's.

This article did not provide me with the solution specifically, but lead me in the right direction. BUT, if your game is going to be in a browser window, you might have to use the same technique of setting wmode to direct or gpu as well.

风铃鹿 2024-07-30 09:44:49

您可能要做的第一件事就是停止将 Flash Player 视为 DOS。 Flash Player 本身就是一个高度优化的 2D 游戏引擎,我真的不明白为什么您要尝试通过复制大量位图切片来重新发明轮子。 当然,你会遇到性能问题。

Flash Player 不允许您同步到任何垂直或水平空白,因为 Flash Player 对此没有任何概念。

我个人认为,如果您想要“更平滑”的动画,您应该重新考虑您的方法。 Flash Player 确实能够做到这一点,您只是尝试了错误的方法。

First thing you might want to do is stop treating the Flash Player like it is DOS. The Flash Player is a highly optimized 2D game engine as it is and I don't really understand why you are trying to reinvent the wheel by copying lots of bitmap slices around. Of course you will have performance issues.

The Flash Player doesn't let you sync to any vertical or horizontal blank because the Flash Player simply doesn't have any concept of this.

I personally think that you should rethink you approach if you want 'smoother' animation. The Flash Player is certainly capable of this, you're just trying the wrong approach.

他是夢罘是命 2024-07-30 09:44:49

不要将内容保存到 BitmapData,这会杀死、绝对杀死你的应用程序。 位图数据的性能不是很好。

在 Flash 中制作所有游戏元素,如 Sprites(或 MovieClips,如果需要的话),然后按照 Flash 的设计方式工作,将其作为矢量动画平台。 它从未针对 2D 位图图形进行优化。 2d 矢量图形效果很好,即使您导入位图,它们也会更好地移动,然后渲染到 BitmapData 对象。

Don't save things to BitmapData, that will kill, absolutely kill your app. Bitmap Data is not very performant.

Make all your game elements in flash, as Sprites(or MovieClips if you must), and then work how flash was meant to work, as a vector animation platform. It was never optimized for 2d bitmap graphics. 2d vector graphics work well, and even if you import bitmaps they will work better moving around then they will rendered to a BitmapData object.

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