我有一個相機類,基本上跟隨地圖上的玩家,並讓他居中在屏幕上。數學即時應用的工作效果很好,直到相機的縮放比例(放大和縮小)被改變。它是:將相機對準對象
x = -cell.x - cell.mass/2 + Game.width/2/sX;
// Where x is the Camera's X, Cell is the Player and sX is the scale factor
我一直在玩不同的方程,但他們都失敗了,一旦規模被改變。我似乎無法環繞此我的頭,我真的可以使用如何在因素它的一些見解
以下是Camera類的一些位:
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(0.9,0.9);
x = -cell.x - cell.mass/2 + Game.width/2/sX;
y = -cell.y - cell.mass/2 + Game.height/2/sY;
}
public double toWorldX(int x){
return x - this.x/sX;
}
public double toWorldY(int y){
return y - this.y/sY;
}
的第一張圖像顯示比例因子爲1(普通縮放)時的結果。第二張圖像顯示比例因子爲0.9(縮小)時的結果。
我提供的會發生什麼圖片 – BruceTheGoose
你的方法沒有解決問題 – BruceTheGoose
你能提供玩家的座標和相機在變焦1和其他一些變焦? –