用于自动将输入缩放到表面分辨率的本机 PyGame 方法?
这个问题与另一个问题相关。
在我的程序中(使用 pygame 在视频上绘制对象)我的世界有两种表示形式
- : 物理模型,我用它来进行模拟中涉及的所有计算,其中对象位于 1000x1000 米的表面上。
- 我用来在屏幕上绘制的视觉对象,其中我的对象位于 100x100 像素的窗口中。
我想要实现的是能够将我的物理/真实坐标传递给我的pygame绘图函数(通常接受像素输入)。换句话说,我希望能够说:
Draw a 20m radius circle at coordinates (200m, 500m)
使用精确的 pygame 语法:
pygame.draw.circle(surface, (255,255,255), (200,500), 20)
并得到以像素(20,50)为中心的 2px 半径的圆。
请注意,这个问题是关于本机 pygame 方法来执行此操作,而不是某种实现该结果的解决方法(如果您想回答这个问题,您应该看看我已经提到)。
预先感谢您的时间和支持。
This question is related to this other one.
In my program (which uses pygame to draw objects on the video) I have two representation of my world:
- A physical one that I use to make all the calculations involved in the simulation and in which objects are located on a 1000x1000 metres surface.
- A visual one which I use to draw on the screen, in which my objects are located in a window measuring 100x100 pixels.
What I want to achieve is to be able to pass to my pygame drawing functions (which normally accept inputs in pixels) my physical/real-word coordinates. In other words, I would like to be able to say:
Draw a 20m radius circle at coordinates (200m, 500m)
using the precise pygame syntax:
pygame.draw.circle(surface, (255,255,255), (200,500), 20)
and get my circle of 2px radius at centred on pixels (20,50).
Please note that this question is about a native pygame way to do this, not some sort of workaround to achieve that result (if you want to answer that, you should take a look to the question I already mentioned) instead.
Thanks in advance for your time and support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有原生的 pygame 方法可以做到这一点。
您可能误解了 pygame 的功能。它不适用于绘制矢量对象。它用于将像素写入视频表面。
由于您有矢量对象,因此必须定义它们如何转换为像素。这样做并不是一种解决方法 - 这是您使用 pygame 的方式。
There is no native pygame way to do this.
You may be misunderstanding the function of pygame. It is not for drawing vector objects. It is for writing pixels into video surfaces.
Since you have vector objects, you must define how they will be converted into pixels. Doing this is not a workaround - it's how you are intended to use pygame.
由于 PyGame 开发人员似乎不会在这里闲逛太多,我将问题带到了 Pygame 邮件列表,它起源于 怪物线程,这个问题已经引起了广泛的争论。
总结如下:
Since it seems that PyGame developers do not hang around here too much, I brought the question to the Pygame mailing list where it originated a monster thread and the issue has been debated at large.
The summary would be: