Results 1 to 2 of 2
  1. #1
    Teedo is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default Screen flickering in parts while scrolling through a map

    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.
    Screen flickering in parts while scrolling through a map-screenshotgraphics.jpg

    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();
            currentMap = map;
            for (GameObject o : currentMap.getGameObjectList()){
                if (o instanceof Player){
        public void paintComponent(Graphics 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.

  2. #2
    Teedo is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default 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

  1. Replies: 9
    Last Post: 09-06-2012, 09:37 AM
  2. Some parts of JFrame off screen
    By cwbr in forum AWT / Swing
    Replies: 9
    Last Post: 01-30-2012, 05:40 PM
  3. Replies: 0
    Last Post: 09-12-2011, 01:06 PM
  4. Screen Flickering
    By dewitrydan in forum New To Java
    Replies: 2
    Last Post: 08-17-2010, 07:45 PM
  5. SWT ExpandBar flickering
    By Tomasz Wroniak in forum SWT / JFace
    Replies: 0
    Last Post: 12-02-2009, 12:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts