the trouble that I see is the
// pitch image is 1266x1694, we just need the frame's size
Image img = ((BufferedImage)getPitchImage()).getSubimage(tmpX, tmpZ, FRAME_WIDTH, FRAME_HEIGHT);
offscreenGraphics.drawImage(img, 0, 0, null);
part of the code. Using the getSubImage routine EVERY time the render method is being called will slow the down the game alot.
And using such a large image as a background is not optimal either. My suggestion is that you make the pitch as tiles, as most of the part is green I quess only on image with dimension of 64x64 or 32x32 should to to paint large part of the pit. The sidelines etc can have specific tiles in the same size. Then save the background tiles as
Image[][] pit
Where pit[0][0] is the top right corner of the soccer pit. And remember only create each tile image ones and then use that tile Image objects refrence in your pit array to avoid massive memory usage.
Then you need some sort of conversion between the pit array images and the coordinates of the frame that needs to be displayed.
// pitch position
// int tmpX = getPosition().getX();
// int tmpZ = getPosition().getZ();
// use instead
Point p = translate(getPosition().getX(), getPosition().getY());
int tmpX = p.x;
int tmpY = p.y;
public Point translate(int x, int y){
return new Point((int) x/TILEWIDTH, (int) y/TILEHEIGHT,
}
Then you need to paint some tiles on your graphic object
int x, y;
for (int i=tmpX; i<(SCREENWIDTH/TILEWIDTH+tmpX); i++)
for (int j=tmpY; j<(SCREENHEIGHT/TILEHEIGHT+tmpY); j++){
g.drawTile(pti[i][j], x, y);
x+=TILEWIDTH;
x+=TILEHEIGHT;
}
I hope you get the idea… you still need to compensate for the offset the translate function makes otherwise the pitch will move one whole tile every 64px or so. This code is not a working one and written in 5 min… just to let you see the concept.