public void update() { if (model.isInitialized()) { model.update(); // Scroll map int scrollBorderLeft = 200; int scrollBorderRight = 200; int scrollBorderUp = 200; int scrollBorderDown = 200; CarDrawInterface car = model.getMyCar(); if (car.getPosX() < (cont.getScrollingOffsetX() + scrollBorderLeft)) { cont.setScrollingOffsetX(car.getPosX() - scrollBorderLeft); } if (car.getPosX() > (cont.getScrollingOffsetX() + cont.getDrawingSizeX() - scrollBorderRight)) { cont.setScrollingOffsetX(car.getPosX() - cont.getDrawingSizeX() + scrollBorderRight); } if (car.getPosY() < (cont.getScrollingOffsetY() + scrollBorderUp)) { cont.setScrollingOffsetY(car.getPosY() - scrollBorderUp); } if (car.getPosY() > (cont.getScrollingOffsetY() + cont.getDrawingSizeY() - scrollBorderDown)) { cont.setScrollingOffsetY(car.getPosY() - cont.getDrawingSizeY() + scrollBorderDown); } // Make sure we don't scroll the map to much if (cont.getScrollingOffsetX() < 0) { cont.setScrollingOffsetX(0); } if (cont.getScrollingOffsetX() > cont.getScrollingSizeX() - cont.getDrawingSizeX()) { cont.setScrollingOffsetX(cont.getScrollingSizeX() - cont.getDrawingSizeX()); } if (cont.getScrollingOffsetY() < 0) { cont.setScrollingOffsetY(0); } if (cont.getScrollingOffsetY() > cont.getScrollingSizeY() - cont.getDrawingSizeY()) { cont.setScrollingOffsetY(cont.getScrollingSizeY() - cont.getDrawingSizeY()); } } }