I would like to know how to move the camera inside the Frame in java. Ex:
frame.moveInsideFrame(pointX,pointY).
I would like to know how to move the camera inside the Frame in java. Ex:
frame.moveInsideFrame(pointX,pointY).
You would have to move everything in the frame. For example:
private void moveInsideFrame(int moveX, int moveY) {
for (int i = 0; i < listOfObjects.size(); i ++) {
JComponent current = listOfObjects.get(i);
current.x -= moveX;
current.y -= moveY;
}
}
(this is just example code, it won't really work. have an ArrayList
of all of your components on screen and move each individually.)
Or, if you just put them all in your frame (instead of overriding paintComponent
in a custom JPanel) then use frame.getComponents()
.
You can consider your outer frame as the "camera" frame, and you can create a "world" frame inside of it. You can then move your world window using opposite coordinates as to emulate the movement of a camera.
To implement it, use an absolute positioning for the inner frame (i.e. no layouts). See http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html for more details on absolute positioning.
I think putting all your objects in a JPanel with a null layout and moving it as a camera is the best solution