Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Problem with panning and scrolling  (Read 876 times)
0 Members and 1 Guest are viewing this topic.
Offline 69_Jeremy_69

JGO n00b
*

Posts: 28


Java games rock!


« on: 2004-12-07 14:40:48 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
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.
Offline 69_Jeremy_69

JGO n00b
*

Posts: 28


Java games rock!


« Reply #1 on: 2004-12-07 14:52:24 »

Nevermind, I had to reverse my X and Y.  They were counting up when they should count down and vice versa.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.09 seconds with 20 queries.