So I tried asking people at the stackoverflow forum and all I get are downvotes. So I’m hoping I get some help here.
Basically im trying to achieve what my title says. I can achieve this but as soon as I thrown in a scale factor it all gets messed up. By messed up I mean that the camera no longer centers itself on the player. Here is my camera class:
import java.awt.*;
public class Camera{
double x, y;
double sX, sY;
public Camera(double x, double y, double sX, double sY){
this.x = x;
this.y = y;
this.sX = sX;
this.sY = sY;
}
public void set(Graphics bbg){
Graphics2D g2 = (Graphics2D)bbg;
g2.translate(x,y);
g2.scale(sX,sY);
}
public void unset(Graphics bbg){
Graphics2D g2 = (Graphics2D)bbg;
g2.translate(-x, -y);
}
public void scale(double sx, double sy){
sX = sx;
sY = sy;
}
public void Update(Cell cell){
scale(1,1);
x = ((-cell.x + cell.mass * 0.5) + Game.width * 0.5)* sX;
y = ((-cell.y + cell.mass * 0.5) + Game.height * 0.5)* sY;
}
public double toWorldX(int x){
return x - this.x / sX;
}
public double toWorldY(int y){
return y - this.y / sY;
}
}
So I ask you, how can I factor in a scale factor to my camera object?