Pygame:位块传输移动背景会产生太多模糊

发布于 2024-08-14 05:27:04 字数 436 浏览 3 评论 0原文

我想做的是创建一个视口来查看背景的一小部分。 (然后放入精灵)。

然而,我注意到的问题是,当它开始移动时,似乎存在背景模糊的问题。我不确定这是否是因为位图传送速度很慢,还是因为代码中存在问题。我正在寻找有关其他人如何 blit 或创建滚动背景的示例,并找到了这篇文章:滚动游戏

我使用了他们的简单示例,果然,当您滚动时,背景会显得模糊(又名用偏移量块传输背景)。我还认为这可能是 FPS 因某种原因而下降,但它根本没有偏离。我不记得其他 2D 游戏有这样的问题。据我所知,由于它不断移动,可能会出现一些运动模糊。只是想知道我是否可以做些什么来缓解这种情况。有人可以补充我可能遗漏的任何内容吗?我将不胜感激任何反馈或帮助。谢谢

What I am trying to do is create a viewport to view a small portion of a background. (And later put sprites in).

However the problem I have noticed is there seems to be an issue of the background blurring when it starts moving. I was not sure if this is because blitting is slow or because of a problem in the code. I was looking for examples on how others blit or create scrolling backgrounds and found this article: Scrolling Games

I used their simple example and sure enough the background appears blurry as you scroll (aka blit the background with an offset). I also thought it might be the FPS dropping for whatever reason however it doesn't deviate at all. I can't recall an issue like this with other 2D games. I understand there may be some motion blur due to it constantly shifting. Just wondering if I can do anything to alleviate this. Can someone chime in on anything I may be missing? I would appreciate any feedback or help. Thank you

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

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

发布评论

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

评论(2

苍暮颜 2024-08-21 05:27:04

我不知道是什么导致了你遇到的问题,但我猜它与双缓冲有关。

您至少使用了两个表面吗?

# preparing two surfaces in __init__()
screen = pygame.display.set_mode((800,600))
background = pygame.Surface(screen.get_size())
background.fill((250, 250, 250))

# called at every step in main loop
# draw images on the background surface
background.blit(image, position)
....

# blit background to screen
screen.blit(background, (0, 0))
pygame.display.flip()

如果直接在屏幕表面绘制图像,则会发生闪烁。

I couldn't know what caused the problem you faced, but I guess it is related to double buffering.

Did you use at least two surfaces?

# preparing two surfaces in __init__()
screen = pygame.display.set_mode((800,600))
background = pygame.Surface(screen.get_size())
background.fill((250, 250, 250))

# called at every step in main loop
# draw images on the background surface
background.blit(image, position)
....

# blit background to screen
screen.blit(background, (0, 0))
pygame.display.flip()

If images are drawn on the screen surface directly, flicking occurs.

ㄖ落Θ余辉 2024-08-21 05:27:04

“模糊”是指背景看起来“加倍”吗?移动正常大小(例如 64x64)精灵时是否会得到相同的效果?

如果您看到双倍,则可能是刷新率问题。打开垂直同步可能会有所帮助。

您获得的帧速率是多少?

如果你把动画放慢到 10 FPS 左右,你是否也会遇到同样的问题?

By "blurry" do you mean that the background appears "doubled"? Do you get the same effect when moving a normal-sized (e.g., 64x64) sprite?

If you are seeing double, then it's probably a refresh rate problem. Turning on vsync may help.

What frame rate are you getting?

If you slow down the animation to around 10 FPS, do you have the same problem?

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