2017-01-01 1 views
1

JPanel에 개체를 렌더링하는 우주 게임을 만들고 있습니다. 이러한 객체의 render 메소드가 My Space 클래스에서 호출됩니다.여러 개체가 렌더링되지 않습니다.

나는 alienShip과 myShip이라는 2 개의 객체를 각 클래스와 함께 가지고 있습니다. 각 클래스에는 렌더링 메소드가 있습니다. 나는 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)를 호출하는 모든 드로어 블 오브젝트를 통해,하지만 해결되지했습니다. 또한 myShip과 동시에 렌더링하는 글 머리 기호가 있습니다.

myShip 및 alienShip은 Ship이라는 추상 클래스도 확장합니다. 희망이 의미가 있습니다.

답변

1

당신은 하나의 항목을 그린 다음 다른 항목을 그려 내려고 그래픽 객체를 보냅니다.

+0

오, 하. 감사! –

관련 문제