出于某种原因,当我将地图放大到15 x 25时,相机会越来越多,在地图的顶部,相机会跳转显示地图的底部,并在底部跳转到顶部。 / p>
以下是代码:
public int getXOffset(){
int offset_x = 0;
//the first thing we are going to need is the half-width of the screen, to calculate if the player is in the middle of our screen
int half_width = (int) (Game.WINDOW_WIDTH/Game.SCALE/2);
//next up is the maximum offset, this is the most right side of the map, minus half of the screen offcourse
int maxX = (int) (map.getWidth()*32)-half_width;
//now we have 3 cases here
if(player.getX() < half_width){
//the player is between the most left side of the map, which is zero and half a screen size which is 0+half_screen
offset_x = 0;
}else if(player.getX() > maxX){
//the player is between the maximum point of scrolling and the maximum width of the map
//the reason why we substract half the screen again is because we need to set our offset to the topleft position of our screen
offset_x = maxX-half_width;
}else{
//the player is in between the 2 spots, so we set the offset to the player, minus the half-width of the screen
offset_x = (int) (player.getX()-half_width);
}
return offset_x;
}
public int getYOffset(){
int offset_y = 0;
int half_heigth = (int) (Game.WINDOW_HEIGTH/Game.SCALE/2);
int maxY = (int) (map.getHeight()*32)-half_heigth;
if(player.getY() < half_heigth){
offset_y = 0;
}else if(player.getY() > maxY){
offset_y = maxY-half_heigth;
}else{
offset_y = (int) (player.getY()-half_heigth);
}
return offset_y;
}
在我的渲染方法中,我使用:
map.render(-(offset_x%32), -(offset_y%32), offset_x/32, offset_y/32, 33, 19);
这是问题的.gif文件,我在这里跳来跳去:http://i.gyazo.com/11efe44d6e872c334533cd3a40ddf2b9.gif
答案 0 :(得分:0)
请尝试使用
,而不是为地图渲染偏移量{{1}}
这种方式更易于管理,你的相机的坐标将与玩家联系在一起。