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
  • 168,117
  • 40
  • 217
  • 433
Matt
  • 51
  • 8
  • 2
    This could be achieved by using an `AffineTransform` on the `Graphics` instance of the custom component. But beware that events and other such things won't be translated. – Andrew Thompson Oct 23 '14 at 06:21
  • Also consider the approach outlined [here](http://stackoverflow.com/a/9373195/230513). – trashgod Oct 23 '14 at 10:24

2 Answers2

0

you just need to subtract y from frame height.

CharlieS
  • 1,432
  • 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
  • 1,069
  • 10
  • 24