Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java custom pixel rendering engine bug

I'm developing my own game engine called FGame, and I am having this graphical error that is really bugging me, and i'm not sure where the problem lies. For graphics, I am using a custom Image class which has a 2d array of pixels to store its data. I also have a screen class, which extends the Image class, and the screen's pixel data is used to draw to the JFrame through the BufferedImage java class.

If I am drawing an image, and I move it around the screen, there is a graphical bug that distorts the pixels in a vertical line at certain spots on the screen.

Here is a video showing the bug I am trying to describe: http://www.youtube.com/watch?v=MnGCuHW5neI, and here is a link to the source code: https://github.com/Frechetta/FGame.

like image 711
Eric Frechette Avatar asked Nov 13 '22 00:11

Eric Frechette


1 Answers

Thank you @arynaq and @Max for helping me with my problem. I'll post my old code and new code for anybody else who runs into this problem.

Old Code:

frame = new JFrame(nameA);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(this, BorderLayout.CENTER);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

New code:

frame = new JFrame(nameA);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
this.setSize(getPreferredSize());
frame.add(this);
frame.pack();
frame.setSize(getPreferredSize());
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
like image 81
Eric Frechette Avatar answered Nov 15 '22 12:11

Eric Frechette