0

I've been working on a little side scroller for fun, and I always wondered how I would "reverse" the JFrame Y coordinates.

Instead of the Y coordinate starting from the top, it should start from the bottom.

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.

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
Matt
  • 51
  • 8

2 Answers2

0

you just need to subtract y from frame height.

CharlieS
  • 1,404
  • 1
  • 9
  • 10
0

Try y-=yAmount or even 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. Your image says that y should start there as 0 and to do that you can do 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.

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; }

JediBurrell
  • 984
  • 9
  • 24