I am writing a basic game in java.
Every renderable object maintains its own coordinates and size. Each object assumes that the origin (0, 0) is where it should be, namely in the upper left corner of the screen.
It seems that the origin is not in the upper left corner but rather somewhere in the negatives. Thus, if I try to draw in object at the origin, it does not appear on screen.
Here is the code I use to obtain the Graphics object used for rendering.
private void renderObjects()
{
Graphics g = buffer.getDrawGraphics();
g.setColor(frame.getBackground());
g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
g.setColor(Color.black);
g.setFont(new Font("Courier", Font.PLAIN, 28));
g.drawString("Score: " + player.getScore() + " Hits: " + player.getHits() + " Misses: " + player.getMisses(), 100, 100);
for(Creature creature: creatures)
{
creature.render(g);
}
buffer.show();
g.dispose();
}
The object "buffer" was obtained and stored in this code:
frame = new JFrame("Duck Hunt");
frame.setPreferredSize(new Dimension(800, 600));
frame.setBackground(Color.white);
frame.getContentPane().addMouseListener(new ClickHandler());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.createBufferStrategy(2);
buffer = frame.getBufferStrategy();
frame.setVisible(true);
Any help or suggetions is appreciated. Thanks.