我有一个相机类,基本上跟随地图上的玩家,并让他居中在屏幕上。数学即时应用的工作效果很好,直到相机的缩放比例(放大和缩小)被改变。它是:将相机对准对象
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和其他一些变焦? –