I am trying to render to a JPanel from a list array. I've created my own 2D renderer, but when I try and add to the list using the RenderAdd function, it either doesn't add, or the list array doesn't allow the list to be read...
He's the code which starts it.
JFrame frame = new JFrame();
frame.setSize(900, 500);
frame.setVisible(true);
Render render = new Render(new RenderDimension(frame.getX(),frame.getY(),frame.getWidth(),frame.getHeight()), frame);
BufferedImage zombie = new ImageLoader().readImage("zombie");
BufferedImage player = new ImageLoader().readImage("player");
render.RenderAdd(new RenderImage(new RenderDimension(100, 100, player.getWidth(), player.getHeight()), player));
render.RenderAdd(new RenderImage(new RenderDimension(0, 0, zombie.getWidth(), zombie.getHeight()), zombie));
render.start();
render.RenderAdd(new RenderImage(new RenderDimension(200, 100, player.getWidth(), player.getHeight()), player));
'render' is the main Render class in the rendering part. Then, RenderAdd adds a RenderImage which has RenderDimension which is the x and y of the object, and the image width and height. Then also takes a BufferedImage as a parameter.
Although, every time I try running the program, it comes with a blank screen
Now, in the Render class, there is another class which extends a thread. This is the class which takes the frame as a parameter, deletes the contents and starts painting to the getContentPane(). This next code is inside the paintComponent() function in the renderthread class. Unfortunately, nothing paints, but is does process because I've tried with System.out.print("h") which repeatedly prints itself.
for (RenderImage r : render.getList()){
int x = r.getSize().getX();
int y = r.getSize().getY();
int wi = r.getSize().getWidth();
int hi = r.getSize().getHeight();
if (x + wi >= -1 && x + wi <= d.getWidth()){
if (y + hi >= -1 && y + hi <= d.getHeight()){
g.drawImage(r.getImage(), x, y, null);
}
}
}
frame.getContentPane().add(p);
frame.getContentPane().validate();
frame.getContentPane().repaint();
I think the problem is that the list won't add, so here's that part.
List<RenderImage> render = new ArrayList<RenderImage>();
public List<RenderImage> getList(){
return render;
}
public void RenderAdd(RenderImage renders){
render.add(renders);
}