pygame中的负坐标
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一个简单的解决方案是编写一个从世界坐标到 pygame 屏幕坐标的线性映射函数
,并在绘制所有世界对象时使用它。请查看此处获取完整示例。
A simple solution is to write a linear mapping function from world coordinates to pygame screen coordinates
and use it when drawing all world objects. Have a look here for a complete example.
无法将曲面的原点从 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.
如果它类似于 RPG 地图情况,其中有世界坐标和屏幕坐标:
使用将世界转换为本地的函数,反之亦然。
但我不确定你是否在寻找 Rect 的属性?
如果您想使用中心坐标进行 blit,则左上角为 (0,0)
另请参阅: 矩形.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?
If you want to use center coordinates to blit, vs top left being (0,0)
See also: Rect.move_ip()
研究你会发现最好的,但也许你可以使屏幕变大并使用正数和函数 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.