I am programming a big game in Java and I am trying to optimize the code, but also so that the code is neat and well organized. Now I'm not sure if I should use a public static field for individual classes that have a couple of variables that are used by multiple instances.
For example, a class camera has an x ββand y position that determines which part of the map the user is viewing and what needs to be displayed on the screen. I am currently comparing with 50,000 units, and I have the following options for drawing them.
1: Save the link to the camera instance in each device and call getX () and getY () when it needs to be drawn:
public void paint()
{
paint(x - camera.getX(), y - camera.getY());
}
2: Put the camera coordinates as arguments for each block when it is drawn:
public void paint(int cameraX, int cameraY)
{
paint(x - cameraX, y - cameraY);
}
3: Make x and y variables for the static camera class:
public void paint()
{
paint(x - Camera.x, y - Camera.y);
}
What interests me is what is usually seen as the best solution and affects performance. Perhaps there are a few more ways to do this that I have not thought about?
Thank!
source
share