The drawImage() method in the game I'm making using Eclipse isn't actually doing anything, and I have no idea why. It just ends up being a blank paint window with nothing being painted at all. Is there any reason for this? The problem is on line 106. Here's my GameEngine code:
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import java.util.List;
import java.util.ArrayList;
/**
* Main class for the game
*/
public class GameEngine extends JFrame
{
boolean isRunning = true;
int fps = 30;
int windowWidth = 500;
int windowHeight = 500;
BufferedImage backBuffer;
Insets insets;
InputHandler input;
int x=windowWidth/2;
int y=windowHeight/2;
int xmove=0;
int ymove=0;
public static void main(String[] args)
{
GameEngine game = new GameEngine();
game.run();
System.exit(0);
}
/**
* This method starts the game and runs it in a loop
*/
public void run()
{
initialize();
while(isRunning)
{
long time = System.currentTimeMillis();
update();
draw();
// delay for each frame - time it took for one frame
time = (1000 / fps) - (System.currentTimeMillis() - time);
if (time > 0)
{
try{Thread.sleep(time);}catch(Exception e){}
}
}
setVisible(false);
}
/**
* This method will set up everything need for the game to run
*/
void initialize()
{
setTitle("Game Demo");
setSize(windowWidth, windowHeight);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
insets = getInsets();
setSize(insets.left + windowWidth + insets.right,
insets.top + windowHeight + insets.bottom);
backBuffer = new BufferedImage(windowWidth, windowHeight, BufferedImage.TYPE_INT_RGB);
input = new InputHandler(this);
objects.add(new Player(100,100));
}
List<Objects> objects = new ArrayList<Objects>(0); //List of all objects in the game
/**
* This method will check for input, move things
* around and check for win conditions, etc
*/
void update()
{
for (int i=0; i<objects.size(); i++){
objects.get(i).act();
}
}
/**
* This method will draw everything
*/
void draw()
{
Graphics g = getGraphics();
Graphics bbg = backBuffer.getGraphics();
bbg.setColor(Color.WHITE);
bbg.fillRect(0, 0, windowWidth, windowHeight);
for (int i=0; i<objects.size(); i++){
bbg.drawImage(objects.get(i).getImage(),objects.get(i).getX(),objects.get(i).getY(),this);
}
g.drawImage(backBuffer, insets.left, insets.top, this);
}
}


