1
私は、オブジェクトをJPanel上にレンダリングする宇宙のゲームを作っています。 これらのオブジェクトのレンダリングメソッドは、私のSpaceクラスで呼び出されます。複数のオブジェクトレンダリングされていない
私は2つのオブジェクトalienShipとmyShipそれぞれのクラスを持っています。各クラスにはレンダリングメソッドがあります。両方の船をJPanelに同時にレンダリングさせることはできません。どちらか一方です。 .render(g2)メソッドを最初に呼び出すオブジェクトのみが表示されます。
SPACE CLASS:
spaceImage=new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
foregroundImage=new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
//create the space Image background and instantiate ships (myShip, alienShip)
//Below render() method is called in my Game class using a standard game loop with
update method and rendor method.
public void render(Graphics2D g) {
Graphics2D g2=(Graphics2D) foregroundImage.getGraphics();
g2.drawImage(spaceImage, 0, 0, null);
myShip.render(g2); <---alienShip does not appear, only myShip.
alienShip.render(g2); <---If I swap these 2 commands, then alienShip appears,
and myShip does not
g.drawImage(foregroundImage, x, x, null);
}
ALIENSHIP AND MYSHIP CLASS:
public void render(Graphics2D g) {
g.drawImage(shipImage, x, y, null);
g.dispose();
}
私はDrawableObject.renderを呼び出して、すべての描画可能オブジェクト(G2)を介してDrawableのインターフェース、およびループを作成しようとしたが、それは修正されません。さらに、私はmyShipと同時にレンダリングするような弾丸を持っています。
myShipとalienShipは、Shipという抽象クラスも拡張します。これが理にかなってほしい。
ああ、ありがとう! –