我上传了一个迷你java游戏的视频 - 我试图将其视为视频。
此处链接:http://www.youtube.com/watch?v=aWQkVivsfbI&feature=youtu.be
所以我的问题:如何在向左/向上处理那些大胆的白色条纹?当向右或向下走时没有问题,我认为它与双缓冲有关,但是据我所知,swing实现了双缓冲,我做了这个.setDoubleBuffered(true); (我的主要课程是扩展JPanel)
任何想法如何解决? = /
这是我的绘画方法:
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);
}
}
}
这是保存所有图像的加载程序,:
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;
}
}
和块类:
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);
}
}
}
}