Results 1 to 5 of 5
  1. #1
    MustSeeMelons is offline Member
    Join Date
    Oct 2012
    Posts
    38
    Rep Power
    0

    Default Active rendering previous frame "noise".

    Hi.
    I have a 2D array of an block object, which has it's own x/y coordinates, color and a render Boolean, so that i can render a grid of squares. In the game render, squares are rendered if it's Boolean is true, skipped otherwise. If I try moving a block, to the left for example, I set the current ones render to false, and the ones on the left to true, but the problem is, that the previous block is still on screen(one third(!?) or even the whole block), although it's render value is false! What could possible cause this?

    GameRender draws the off screen image:
    Java Code:
    public void gameRender(){
    		if(buffer==null){
    			buffer=new BufferedImage(W,H, BufferedImage.TYPE_INT_RGB);
    			if(buffer==null){
    				System.out.println("Failed to create buffer!");
    				return;
    			}
    			else{
    				g2d=(Graphics2D) buffer.getGraphics();
    			}
    		}
    		g2d.setColor(Color.cyan);
    		g2d.fillRect(0, 0, W, H);
    		for(int i=0;i<ROWS;i++){
    			for(int j=0;j<COLUMNS;j++){
    				if(Boolean.valueOf(gameBoard[i][j].render)){
    					g2d.setTransform(identity);
    					g2d.translate(gameBoard[i][j].x, gameBoard[i][j].y);
    					g2d.setColor(gameBoard[i][j].color);
    					g2d.fillPolygon(gameBoard[i][j].shape);
    					g2d.setColor(Color.red);
    					g2d.draw(gameBoard[i][j].shape);
    				}
    			}
    		}
    	}
    Paint the buffer on screen:
    Java Code:
    public void paintScreen(){
    		Graphics g;
    		 try {
    		   g = this.getGraphics();
    		   if((g != null) && (buffer != null))
    		   g.drawImage(buffer, 0, 0,null);
    		   Toolkit.getDefaultToolkit().sync();
    		   g.dispose();
    		 }
    		 catch (Exception e)
    		 { System.out.println("Error blitting: " + e);  }
    	}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

    Default Re: Active rendering previous frame "noise".

    Don't tell me you're still using AWT components/code in this day and age!

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Active rendering previous frame "noise".

    Actually if you want to do "active rendering" for a game using Java2D, its my preferred method to stick to low level AWT. But I'd investigate using a simple Canvas combined with a BufferStrategy to do double buffering in stead of painting to a BufferedImage.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    MustSeeMelons is offline Member
    Join Date
    Oct 2012
    Posts
    38
    Rep Power
    0

    Default Re: Active rendering previous frame "noise".

    Quote Originally Posted by DarrylBurke View Post
    Don't tell me you're still using AWT components/code in this day and age!

    db
    What should I be using then?

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Active rendering previous frame "noise".

    Anything not Java2D related is better. LibGDX is pretty much a new standard for Java and (2D) game development.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  3. how to create a "child" frame.
    By Shellback3 in forum AWT / Swing
    Replies: 4
    Last Post: 02-02-2011, 04:48 AM
  4. Get "Frame"(?) as a methode
    By Mattedatten in forum New To Java
    Replies: 3
    Last Post: 11-10-2009, 12:31 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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