gpt4 book ai didi

python - pygame中的负坐标

转载 作者:太空宇宙 更新时间:2023-11-04 06:30:40 24 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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

并在绘制所有世界对象时使用它。看看here一个完整的例子。

关于python - pygame中的负坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3279436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com