[英]Reversing the JFrame Y coordinate?
I've been working on a little side scroller for fun, and I always wondered how I would "reverse" the JFrame
Y coordinates. 我一直在研究一个小的侧面滚动条,很有趣,我一直想知道如何“反转” JFrame
Y坐标。
Instead of the Y coordinate starting from the top, it should start from the bottom. 应该从底部开始而不是从顶部开始的Y坐标。
I made a fancy diagram to make things more clear: 我制作了一张花哨的图表,以使情况更清楚:
This is nothing that would be useful to me at thus point in time. 在目前的时间点上,这对我没有什么用。 But it would be good to know how to do it if for some reason I would need to do it. 但是,如果出于某种原因我需要这样做,最好知道如何去做。
您只需要从框架高度中减去y。
Try y-=yAmount
or even y--;
尝试y-=yAmount
甚至y--;
Let me explain, x and y start at 0, that is the top left corner, adding to x and/or y will put it lower to the right. 让我解释一下,x和y从0(即左上角)开始,加到x和/或y会使它向右下方。 Your image says that y should start there as 0 and to do that you can do int y2 = 0; int y = offsetY + y2;
您的图片显示y应该从0开始,并且可以做到int y2 = 0; int y = offsetY + y2;
int y2 = 0; int y = offsetY + y2;
by doing that all you have to do is set y2, y and make sure that offsetY is set to your current y to make it a relative change. 通过做所有您需要做的设置y2,y并确保将offsetY设置为当前y使其相对变化。
Here is a few functions you could use 这是您可以使用的一些功能
public void changePositionRelative(int xChange, int yChange){ x += xChange; y += yChange; }
public void resetPosition(){ x = offsetX; y = offsetY; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.