pygame中的负坐标

发布于 2024-09-10 14:07:56 字数 124 浏览 9 评论 0原文

在 pygame 中使用负坐标的最佳方法是什么?

目前,我的曲面是原始曲面的 1.5 倍,然后将需要绘制的所有内容向上移动一定量(以确保负坐标变为正坐标)并绘制。

有没有更简单/替代的方法来做到这一点?

What would be the best way to use negative coordinates in pygame?

At the moment I have a surface that is 1.5 times the original surface then everything that needs to be drawn is shifted up by a certain amount (to ensure the negative coordinates become positive) and drawn.

Is there an easier/alternate way of doing this?

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

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

发布评论

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

评论(4

ゃ懵逼小萝莉 2024-09-17 14:07:56

一个简单的解决方案是编写一个从世界坐标到 pygame 屏幕坐标的线性映射函数

def coord(x,y):
    "Convert world coordinates to pixel coordinates."
    return 320+170*x, 400-170*y

,并在绘制所有世界对象时使用它。请查看此处获取完整示例。

A simple solution is to write a linear mapping function from world coordinates to pygame screen coordinates

def coord(x,y):
    "Convert world coordinates to pixel coordinates."
    return 320+170*x, 400-170*y

and use it when drawing all world objects. Have a look here for a complete example.

难如初 2024-09-17 14:07:56

无法将曲面的原点从 0,0 移动。

实现您自己的绘图类,它将传入的所有坐标转换为表面空间。

There is no way to move the origin of a surface from 0,0.

Implement your own drawing class which transforms all the coordinates passed in into the space of the surface.

绻影浮沉 2024-09-17 14:07:56

如果它类似于 RPG 地图情况,其中有世界坐标和屏幕坐标:
使用将世界转换为本地的函数,反之亦然。

但我不确定你是否在寻找 Rect 的属性?

rect.bottomright = (width, height) # bottom right at window corner

如果您想使用中心坐标进行 blit,则左上角为 (0,0)

ship.rect.center = (20, 30) # don't need to translate by adding w/2 to topleft

另请参阅: 矩形.move_ip()

If it's similar to an RPG map situation, where you have world coordinates and screen coordinates:
use a function that translates world to local, and vice versa.

But I wasn't sure I'd you were looking for Rect's properties?

rect.bottomright = (width, height) # bottom right at window corner

If you want to use center coordinates to blit, vs top left being (0,0)

ship.rect.center = (20, 30) # don't need to translate by adding w/2 to topleft

See also: Rect.move_ip()

梦境 2024-09-17 14:07:56

研究你会发现最好的,但也许你可以使屏幕变大并使用正数和函数 b.screensize(1000,1000) #1000 和 1000 只是示例,你应该在那里输入整数来扩大屏幕。

Research you will find the best, but Maybe you can make screen large and use positive numbers with function which is b.screensize(1000,1000) #1000 and 1000 are just example , you should enter integer there to expand the screen.

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