Results 1 to 2 of 2
- 08-18-2013, 10:36 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 61
- Rep Power
- 0
Screen flickering in parts while scrolling through a map
Hello,
I am creating an RPG where the player is centered on the screen (JPanel), and the screen will scroll around the map. It works fine except when moving left and up, there will be graphics problems (screen tearing? Though I thought swing/paintcomponent uses double bufering). It doesn't happen when moving right or down for some reason. I will just paste my rendering code as i'm pretty sure it has something to do with that. I tried taking a screenshot of the graphics problem but it will not capture it, so instead I drew what it looks like myself. I have a theory that the tiles are rendering one by one which could cause the tearing, rather than using double buffering and flipping the page.
Thanks :)
EDIT: The lines actually go the whole height of the screen. Though when moving up, the lines are horizontal and only about 32 pixels wide.
Java Code:public class GameScreen extends JPanel { private List<Map> mapList; private JTextField tfFPS; private int posX; private int posY; private BufferedImage image; private Map currentMap; public GameScreen(DesolatedSpirits ds){ super(true); // Set double buffering tfFPS = new JTextField(); mapList = new ArrayList<Map>(); Map map = new Map(); map.loadMap("maps/town1.dsmap"); currentMap = map; ds.getGameEngine().setCurrentMap(map); tfFPS.setEditable(false); this.setBackground(Color.black); this.add(tfFPS); for (GameObject o : currentMap.getGameObjectList()){ if (o instanceof Player){ this.setPosX(o.getPosX()); this.setPosY(o.getPosY()); } } } @Override public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); if (currentMap != null){ for (GameObject o : currentMap.getGameObjectList()){ g2d.drawImage(o.getCurrentGraphic(), o.getPosX()-posX, o.getPosY()-posY, this); } } }
Last edited by Teedo; 08-18-2013 at 12:11 PM.
- 08-18-2013, 12:39 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 61
- Rep Power
- 0
Re: Screen flickering in parts while scrolling through a map
I have managed to fix it. The tiles were getting moved in the middle of repainting because the repainting mustn't be done in the same thread that repaint() is called :). I had repaint called during my gameloop and thought it would finish painting before it continue, so instead I just made a boolean to check whether its still painting before the tiles movement is updated.
Last edited by Teedo; 08-18-2013 at 11:12 PM.
Similar Threads
-
How to screen capture a running full screen DirectX program in Java?
By MEdiQueen in forum Advanced JavaReplies: 9Last Post: 09-06-2012, 09:37 AM -
Some parts of JFrame off screen
By cwbr in forum AWT / SwingReplies: 9Last Post: 01-30-2012, 05:40 PM -
Public API for Custom XML Parts & Custom Parts, Graphics Rendering
By sherazam in forum Java SoftwareReplies: 0Last Post: 09-12-2011, 01:06 PM -
Screen Flickering
By dewitrydan in forum New To JavaReplies: 2Last Post: 08-17-2010, 07:45 PM -
SWT ExpandBar flickering
By Tomasz Wroniak in forum SWT / JFaceReplies: 0Last Post: 12-02-2009, 12:23 PM
Bookmarks