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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | 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 ); } } |