public void updateOffset(){
    final int tilesPerX = WINDOW_X/TileData.TILE_X, tilesPerY = WINDOW_Y/TileData.TILE_Y;
    final int width = map.getWidth(), height = map.getHeight();
    final int posX = ((CMoving)player.getComponent(CMoving.class)).getX(), posY = ((CMoving)player.getComponent(CMoving.class)).getY();
    if(width <=tilesPerX)
      offset.x = WINDOW_X/2- width*TileData.TILE_X/2; 
    else{
      if(posX < tilesPerX/2)
        offset.x = 0;
      else if(posX > width - tilesPerX/2)
        offset.x = (tilesPerX/2 - width)*TileData.TILE_X+WINDOW_X/2;
      else
        offset.x = WINDOW_X/2-posX*TileData.TILE_X;
    }
    
    if(height <=tilesPerY)
      offset.y = WINDOW_Y/2- height*TileData.TILE_Y/2;    
    else{
      if(posY < tilesPerY/2)
        offset.y = 0;
      else if(posY > height - tilesPerY/2)
        offset.y = (tilesPerY/2 - height)*TileData.TILE_Y+WINDOW_Y/2;
      else
        offset.y = WINDOW_Y/2-posY*TileData.TILE_Y;
    }
  }