Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with panning and scrolling  (Read 1156 times)
0 Members and 1 Guest are viewing this topic.
Offline 69_Jeremy_69

Senior Newbie




Java games rock!


« Posted 2004-12-07 19: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

Senior Newbie




Java games rock!


« Reply #1 - Posted 2004-12-07 19: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (22 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (55 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (29 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!