Is this possible? For I am trying it, and currently it is not working…
Won’t do as last time and post all the code
Here’s the object with the paintComponent():
public Platform() {
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.gray);
g.fillRect(0, 0, getBounds().width, getBounds().height);
The Platform-object is created first here:
private class Level extends JPanel implements KeyListener, ActionListener {
Platform ground = new Platform();
Platform p1 = new Platform();
Platform p2 = new Platform();
Platform p3 = new Platform();
public Level() {
setPreferredSize(new Dimension(400, 400));
ground.setBounds(0, 380, 400, 20);
p1.setBounds(150, 200, 100, 20);
p2.setBounds(100, 300, 200, 20);
p3.setBounds(100, 360, 40, 20);
add(ground);
add(p1);
add(p2);
add(p3);
}
(This private class does also have a paintComponent(), is that the problem…?)
Then the Level object is added to the JFrame in the superclass.
The mechanics of the platformer works just as I want it now, but having invisible platforms bothers me a bit : D