Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Image "flickers", need help!

  1. #1
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Angry Image "flickers", need help!

    Hi!

    Im currently making a game with a rpg tile-based world. The problem is that the world gets "cracks" as if it flickers. I have never encountered this problem before and have no idea what it is.
    In the original edit I will not post any code since I do not know in which section the problem might occur, however, I will attach an image displaying the error.

    game_example.jpg

    I should also mention that the error only occur when the player's x or y velocity is negative.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Image "flickers", need help!

    Flickering is a common problem, and unfortunately can be caused by many things.

    Since graphics can be handled in so many ways, start off by giving a general summary of how you handle your drawing. (are you buffereing manually, double triple buffering, using a strategy, page flipping, etc?)
    Include any code snippets you have that you think may be running a bit sluggish.

  3. #3
    Member
    Join Date
    Jun 2012
    Location
    Uppsala, Sweden
    Posts
    36
    Thanks
    10
    Thanked 1 Time in 1 Post

    Default Re: Image "flickers", need help!

    Hi!

    I have picked out some code snippets that could cause the problem. The first example is the drawing code of my main JPanel. This is were my buffering takes place.

    	@Override
    	public void update(Graphics arg0) {
     
    		paint(arg0);
    	}
     
    	@Override
    	public void paint(Graphics arg0) {
     
     
    		Graphics2D g = (Graphics2D) arg0;
     
    		bufferGraphics.clearRect(0, 0, getSize().width, getSize().height); //bufferGraphics = offscreen.getGraphics();
     
    		screen.drawScreen(bufferGraphics);
     
    		g.drawImage(offscreen, 0, 0, this);	
    	}

    I also decided to post my code for drawing the level.
    The way this is supposed to work is, that it renders all tiles inside the screen borders + 4 tiles outside each border.

    @Override
    	public void render(Graphics2D g) {
     
    		int var0 = level.getTileset().getTileSize();
     
    		for (int i = 0; i < level.world.length; i++) {
     
    			if (i * var0 + level.xOffset > level.getSize().width + var0 * 4) break;
     
    			if (i * var0 + level.xOffset + var0 < - (var0 * 4)) continue;
     
    			for (int j = 0; j < level.world[0].length; j++) {
     
    				if (j * var0 + level.yOffset > level.getSize().height + var0 * 4) break;
     
    				if (j * var0 + level.yOffset + var0 < -(var0 * 4)) continue;
     
    				TileStack var1 = level.world[i][j];
     
    				var1.getTile().getRenderer().renderWithMetadata(g, level.getTileset(),
    						i * var0 + level.xOffset, j * var0 + level.yOffset, var1.getMetadata());
    			}
    		}
    	}

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Image "flickers", need help!

    Is the crack in a permanent location on the screen as you walk and the map scrolls? ..Is it in a permanent location on the map, ie the crack moves with the ground?

    I should have read more of the original post, I got to the word "flickers" and the rest is a blur. Now that I look at it again your last comment is a large hint to finding the cause.

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  3. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  4. Replies: 2
    Last Post: June 29th, 2009, 03:06 PM
  5. Replies: 4
    Last Post: June 18th, 2009, 09:23 AM

Tags for this Thread