Ok game one I created a top down view scoller. And just incremented my Y and used
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
ImageObserver observer)
Works fine.
So for game 2 I create a top down view game. That the user can scroll. Seemed simple enough.
What I have:
Screen 640x480
Image 1024x780 (variable background)
Viewable area 640x300
edgeX - tracks panning.
edgeY - tracks panning.
I create my fullscreen frame, I draw the image of my level. It only show the top left corner. Cool
So I add a JPanel of that size of the Viewable area to the frame, then add a mouse listener.
Now I create a function to track if the mouse is on the edge of the panel borders. If true I increase/decrease the X or Y. As long as its within the limits of the source.
This all works lovely.
Problem I encounter is when I scroll it just scrolls around within the limits but the new viewbla area is black (background color). The image is not staying anchored.
public void render(){
if(!strategy.contentsLost())
{
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0,0,screenWidth, screenHeight);
g.drawImage(background,
0,0,screenWidth,screenHeight,
edgeX,edgeY,
edgeX+screenWidth,edgeY+screenHeight,
window);
g.setColor(Color.BLUE);
g.fillRect(hudX,hudY,hudWidth, hudHeight);
paintStatus(g);
strategy.show();
g.dispose();
}
}
Am I using the wrong call to draw the image. Should I be creating a subimage of background and drawing that?
Assuming you had the X and Y what would you do. I want to show a 640x300 area of the image called background (var name). Starting at edgeX and edgeY.