GeneralPath 未按更改比例绘制
我目前正在制作一款横向卷轴游戏,该游戏使用随机生成的地形在后台滚动。地形基本上是 GeneralPath 类的一个实例。当地形生成时,角点 (0, 0) 和 (width, 0) 包含在路径中,因为查看画布的高度尚不清楚。为了使地形显示为正面朝上,我添加了以下几行代码:
g.translate(0, getHeight());
g.scale(0, -1);
这应该将坐标系翻转为笛卡尔格式,左下角为 0, 0。 由于某种原因,地形没有绘制。当我注释掉这些行时,它可以工作,但是是颠倒的。如果我只注释掉缩放命令并将翻译量更改为较小的数字,它也会成功绘制(颠倒并翻译少量)。
提前致谢!
Im currently making a sidescroller game which uses randomly generated terrain that scrolls in the background. The terrain is basically an instance of the GeneralPath class. When the terrain generates, the corners (0, 0) and (width, 0) are included in the path since the height of the viewing canvas isnt known yet. To make the terrain appear right-side-up, i added the following lines of code:
g.translate(0, getHeight());
g.scale(0, -1);
This should flip the coordinate system into Cartesian format with the bottom left being 0, 0.
For some reason, the terrain isnt drawing. When i comment-out these lines, it works, but is upside-down. If i only comment out the scale command and change the amount translated by to a smaller number, it also draws successfully (upside-down and translated a small amount).
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所注意到的,您还需要缩放 x 轴 - g.scale(1, -1);
As you noticed, you need to scale the x axis as well - g.scale(1, -1);