Hello! I've been doing HTML for a while and now am returning to Java after a few months, and I can tell I've lost a few things...
Right now, I'm trying to develop a very basic layout for an RPG. It will be the top-down view sort of RPG, and I have it working so that the arrow keys can be used to move around the screen. The only problem is the level won't paint. I have an extension of JPanel called LevelPanel that holds all the information for the player and the objects of a level, and a class called Renderer uses an instance of LevelPanel to draw the level. LevelPanel's paintComponent method is overridden to invoke the Renderer class's renderLevel method, which as I stated before draws the level, its objects, and the player. A JFrame is being used to hold the panel. The frame has a Swing Timer that fires every 1/40th of a second to update the display of the LevelPanel so that when the user moves or collects an item his/her action is seen.
Unfortunately, nothing is drawn. I've put printlns throughout the Renderer class and they all get printed, but the frame is never painted upon.
Renderer:
public static void renderLevel(LevelPanel l) { Graphics g = l.getGraphics(); Graphics2D g2 = (Graphics2D)g; System.out.println("Filling background"); g2.setColor(Color.BLACK); g2.fillRect(0, 0, l.getLevel().getxSize(), l.getLevel().getySize()); //drawing spawn System.out.println("Drawing spawn"); g2.setColor(Color.GRAY); g2.fillOval(l.getLevel().getSpawnPoint().x, l.getLevel().getSpawnPoint().y, 10, 10); //drawing collectable objects System.out.println("Drawing objects"); for(CollectableObject i : l.getLevel().getItems()) { i.draw(g2); } //drawing player System.out.println("Drawing player"); l.getPlayer().draw(g2); }
Is the panel not being drawn because repaints are being requested to often? I would find that odd, since I have another project that uses a similar concept and updates faster than this one...
Am I missing something? Any suggestions would be appreciated...