Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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  
  Games & Gui  (Read 1784 times)
0 Members and 1 Guest are viewing this topic.
Offline stef569

Junior Devvie





« Posted 2008-04-12 01:59:20 »

Ok here it goes.

I'm making a simple 2D tile game, would it be smart to goto slick instead of java2d as i'm doing now?
I only paint images, all 2D.
atm i'm using swing Actively rendering and it flickers as you can see here(move your mouse to the left and right edge)
http://www.kwbbz.be/Downloads/Java/versions/test/test.jnlp
the tile image itself also flickers(while it doesn't get moved around)
I don't know how to fix it, I need a hud to display stuff and I only know Swing
When I won't use Swing is everything drawen at a fixed pixel position?
Offline stef569

Junior Devvie





« Reply #1 - Posted 2008-04-12 20:43:40 »

Swing doesn't flicker when I don't move stuff around(except for the Tile Image)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
    
  public void moveOverTile(Tile t) {
    Point leftTop = mapPanel.getLeftTop();
    Dimension mapPanelDim = mapPanel.getSize();
    if (t == null) {
      return;
    }

    // Is the current Tile position on the left side of the mapPanel(viewArea)
    boolean move = leftTop.x + (t.getCol() * map.getTileSize()) <= mapPanel.getWidth() / 2;

    // check for change
    if (leftSide != move) {
      leftSide = move;

      if (leftSide) {
        tileInfo.setAbsolutePosition(mapPanelDim, TileInfo.Position.LOWER_RIGHT);
      } else {
        tileInfo.setAbsolutePosition(mapPanelDim, TileInfo.Position.LOWER_LEFT);
      }
    }
}


TileInfo:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
  public void setAbsolutePosition(Dimension dim, Position pos) {
    Point currentLocation = getLocation();
    int x = 0, y = 0;
    switch (pos) {
      case LOWER_LEFT:
        x = LEFT_MARGIN;
        y = dim.height - HEIGHT - BUTTOM_MARGIN;
        break;
      case LOWER_RIGHT:
        x = dim.width - WIDTH - LEFT_MARGIN;
        y = dim.height - HEIGHT - BUTTOM_MARGIN;
        break;
    }

    // If one coordinate changed we need to change it's position!
    if (x != currentLocation.x || y != currentLocation.y) {
      setLocation(x, y);
    } else {
      System.out.println("stop calling this function, i already changed...");
    }
  }


I don't see the System.out message so that's good :p
before i was setting the location for every update, but that wasen't the cause of the problem... I still get Flickering.

When setLocation is called i can see a rectangle from old to new position being drawen in the background color(grey)
the rectangle has the same height as TileInfo.getHeight and the width is the same as TileInfo.getWidth()
what can be the cause of this rectangle?
I think it's some kind of dirty rectangle but that's supposed to be blocked?

I disabled automatic repaintings as in http://www.java-gaming.org/forums/index.php?topic=15140.15
so how does that rectangle get's there anyway?
Offline stef569

Junior Devvie





« Reply #2 - Posted 2008-04-13 12:01:25 »

I solved it  Grin

First remove the panel
update the position
add the panel again
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Devvie





« Reply #3 - Posted 2008-04-14 03:47:25 »

Though this isn't what you're asking about, here is some feedback.

The usual thing to do is to override the paintComponent method of the panel and draw whatever part of the map is visible.  Instead of changing the position of the panel, just store variables indicating which tile is currently at the top-left and draw whatever tiles are currently visible.

Additionally, it would be better if you couldn't scroll past the edge of the map, though that's a separate issue.

I didn't play the game; I just looked at it and scrolled around.
Offline stef569

Junior Devvie





« Reply #4 - Posted 2008-04-21 16:38:38 »

Though this isn't what you're asking about, here is some feedback.

The usual thing to do is to override the paintComponent method of the panel and draw whatever part of the map is visible.  Instead of changing the position of the panel, just store variables indicating which tile is currently at the top-left and draw whatever tiles are currently visible.

Additionally, it would be better if you couldn't scroll past the edge of the map, though that's a separate issue.

I didn't play the game; I just looked at it and scrolled around.

Noo, you misunderstand me  Cheesy
The 'InfoPanels' that show tile & unit information that's are the ones that flicker badly when moved using setPosition()
I do scroll using a leftTop Point.

Agreed need to fix the out of bound scrolling(having problems with it)

and draw whatever tiles are currently visible.
I just draw every Tile in the map, aren't drawing operations outside the panel bounds ignored?
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #5 - Posted 2008-04-21 17:53:23 »

I just draw every Tile in the map, aren't drawing operations outside the panel bounds ignored?

No.  Drawing still occurs if you call a draw routine.  Even if the surface is outside of the visible area. 

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.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!