Pygame 缩放/滚动窗口

发布于 2024-10-17 12:52:27 字数 375 浏览 5 评论 0原文

我目前正在使用 pygame 进行一个项目,并且需要能够查看表面的一部分、四处移动、放大和缩小等。

任何人都可以推荐一种有效实现此目标的方法吗?我让它以一种复杂的方法在但它太慢了,当缩小以查看整个区域时,游戏速度会降低到大约 1 fps。 (我的版本只有滚动,没有缩放工作正常,没有滞后)

虽然文档 pygame.transform.scroll 看起来很有希望,但我不确定如何使用 pygame.transform.scale 正确实现它以进行放大和缩小

欢迎任何帮助

更新: 我摆弄了一下,让它在块传输之前缩放对象及其位置。我现在遇到了一个问题,由于 pygame 滚轮事件的分辨率较低,缩放看起来不自然,所以我现在尝试实施某种平滑。

Im currently working on a project with pygame and am in need of being able to view part of a surface, moving around, zooming in and out ect

Can anyone recommend a way of achieving this efficently, i have it working in a convoluted method at the moment but it is too slow and reduces the game to about 1fps when zoomed out to view the whole area. (my version of only scrolling and no zooming works fine with no lagging)

Looking though the docs pygame.transform.scroll looks promising but i am unsure how i would correctly implement it with pygame.transform.scale for zooming in and out

Any help welcome

update:
I fiddled around for a bit and got it working scaleing objects and their positions before bliting them. I have now hit the problem that the scaling looks unatural because of the low resolution of the pygame scroll wheel events so I am now trying to impliment some kind of smoothing.

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

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

发布评论

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

评论(3

昔梦 2024-10-24 12:52:27

我不完全确定你到底在做什么。然而我可以说,听起来你并没有以适合 Pygame 的方式解决这个问题。

在我看来,您正在依赖软件缩放算法(Pygame 使用的算法)将大图片(整个游戏世界)缩放到小得多的尺寸。对于大表面和每个帧,任何类似的事情都会极大地消耗您的 CPU。

如果缩放确实很重要,我建议更改具有硬件加速缩放的库,即 pyglet。毕竟,在 GPU 出现之前,您有多少次看到游戏缩小了?几乎从来没有,就是这么频繁。

I am not entirely sure what, exactly, you are doing. I can however say that it doesn't sound like you are approaching the problem in a way that fits Pygame.

It sounds to me like you are relying on software scaling algorithms, which is what Pygame uses, to scale a large picture (the entire game world) to a much smaller size. Anything like that, for large surfaces, and on each frame, is going to greatly strain your CPU.

If zooming is really important, I'd recommend a change to a library that has hardware accelerated scaling, i.e pyglet. After all, how often did you see games zoom out in the days before GPUs? Virtually never, that's how often.

天赋异禀 2024-10-24 12:52:27

您可以将 pygame 与 OpenGL 结合使用,因为您已经熟悉 pygame。除此之外,pyglet 是一个类似的 opengl 库。

You can use pygame with OpenGL, since you are already familiar with pygame. Otherwise pyglet is a similar opengl library.

左秋 2024-10-24 12:52:27

对于我从未完成的游戏,我使用三角学通过自由缩放和转动的相机(有点复杂)来获得新的绘图位置。计算并没有花费太多时间,但我认为使用其他库更有效。但如果您想要一些例子,请询问。

For a game that I have never finished I used trigonometry to get the new drawing positions with a freely zoomed and turned camera (bit complicated). It didn't really take to much time to calculate but I think it is more efficient to use other libraries. But if you want some examples just ask.

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