How to bring an image to the foreground in Java?

后端 未结 3 1906
盖世英雄少女心
盖世英雄少女心 2021-01-27 07:10

I\'m trying to create a Pacman game in Java, and so far I\'ve displayed the background image (the blue and black maze), but I\'m having trouble showing the image of Pacman. When

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 07:50

    window.add(pacman);
    window.add(panel);
    

    You're adding pacman before you add the background, so it is drawing over the pacman sprite and you are not seeing it. Make sure you draw your items in the game in reverse order, so draw the background first, then pacman.

提交回复
热议问题