double buffering? ... or?

131 views Asked by At

I uploaded a video of my mini java game - i've tried to catch it as a video.

here the link: http://www.youtube.com/watch?v=aWQkVivsfbI&feature=youtu.be

so my question: How to handle that bold white stripes while going to the left / up ? When going right or down there is no problem, i think it has to do with double buffering but swing implements double buffering as far as i know and i did this.setDoubleBuffered(true); (my main class is extending JPanel)

Any ideas how to solve? =/

Here is my paint method:

public void paintComponent(Graphics g){
    super.paintComponent(g);

    if(started){
        for(ListIterator<Chunk> it = chunkvector.listIterator();it.hasNext();){
            Chunk r = it.next();
            r.drawChunk(g);
        }

        for(ListIterator<Sprite> it = vectorpainter.listIterator();it.hasNext();){
            Sprite r = it.next();
            r.drawObjects(g);
        }
        for(ListIterator<Animo> it = animovectorpainter.listIterator();it.hasNext();){
            Animo r = it.next();
            r.drawObjects(g);
        }
        //Chat

        if(coni.verified){
        try {
            chat.update(g);
        } catch (IOException e) {
            System.out.println("I/O Exception while updating chat! "+e.toString());
        }
        }

        //Framerate Anzeige
        if(fps_on){
            g.setColor(Color.red);
            g.drawString("FPS: "+Integer.toString(fps), 20, 20);
        }
        //Tickberechnung & Anzeige
        tick++;
        if(tick==65536)
                tick=0;
        if(tick_on){
            g.setColor(Color.red);
            g.drawString("Tick: "+Integer.toString(tick),80,20);
        }
    }

}

Thats the loader which keeps all the images, :

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;


public class AnimLoader {
    BufferedImage[] chatgui,andi,arrowpic,chunks;

    public AnimLoader(){
        chunks = new BufferedImage[4];
        chunks[0] = loadPics("textures/grass.jpg",1)[0];
        chunks[1] = loadPics("textures/grass1.jpg",1)[0];
        chunks[2] = loadPics("textures/grass2.jpg",1)[0];
        chunks[3] = loadPics("textures/grass3.jpg",1)[0];
        chatgui = loadPics("UI/chatbackground.png",1);
        andi = loadPics("players/andi.gif",1);
        arrowpic = loadPics("objects/arrow.gif",1);
    }

    private BufferedImage[] loadPics(String path, int cnt){
        BufferedImage[] anim = new BufferedImage[cnt];
        BufferedImage source = null;

        URL pic_url = getClass().getResource(path);
        try{
            source = ImageIO.read(pic_url);
        }catch(IOException e){
            System.out.println(e.toString());
        }

        for(int x=0;x<cnt;x++){
            anim[x]=source.getSubimage(x*source.getWidth()/cnt, 0, 
                    source.getWidth()/cnt, source.getHeight());
        }
        System.out.println(pic_url+" - loaded.");
        return anim;        
    }
}

And the chunk class :

public class Chunk {
private int[][] field;
long x,y;
Game parent;
int size;
//(X|Y) Coordinates from upper left corner of chunk
BufferedImage[] pics;

public Chunk(AnimLoader al,long x, long y, Game p,int size){
    this.size=size;
    field = new int[size][size];
    pics=al.chunks;
    this.x=x;
    this.y=y;
    this.parent= p;
    //StandardInitialising
    for(int i=0;i<size;i++){
        for(int j=0;j<size;j++){
            field[i][j]=(int)(Math.random()*4);
        }
    }

}

public void drawChunk(Graphics g){
    for(int i=0;i<size;i++){
        for(int j=0;j<size;j++){
            g.drawImage(pics[field[i][j]],(int) ((50*i)-parent.getplayerx()),(int) ((50*j)-parent.getplayery()),null);
        }
    }
}

}

0

There are 0 answers