0

だから私は一種の束縛に陥っています。ここに私の問題があります

タイルを描画できますが、プレーヤー (JPanel) を描画すると、他の JPanel (マップ情報を格納する) をカバーします。

これを行うことについて私が考えた方法は、layeredPane を使用して JPanels のグリッドを作成し、さまざまなレイヤーを作成することです (したがって、ユニットがツリーの下を歩くと、それらを見ることはできません)。各正方形の間に滑らかなアニメーションを作成できます。

レイアウト マネージャーでスムーズな動きを実現する方法はわかりませんが、レイアウト マネージャーについてはよくわかりません。これを整理したら、マップ エディターで作業を開始できます。

Java の知識を深めるためにこの RPG ゲームを書いています。

//This is a snippet in the player class.
//Objects in here have already been instantiated and loaded, also the class implements
//Action Listener, which calls to repaint the unit.
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D)g;
    if(GlobalObjects.playerSpriteImageAlternater == 1){
        g2d.drawImage(unitBodyBackward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairBackward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesBackward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();

    }else if(GlobalObjects.playerSpriteImageAlternater == 2){
        g2d.drawImage(unitBodyBackward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairBackward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesBackward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();

    }else if(GlobalObjects.playerSpriteImageAlternater == 3){
        g2d.drawImage(unitBodyRightway1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairRightway1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesRightway1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }else if(GlobalObjects.playerSpriteImageAlternater == 4){
        g2d.drawImage(unitBodyRightway2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairRightway2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesRightway2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }else if(GlobalObjects.playerSpriteImageAlternater == 5){
        g2d.drawImage(unitBodyForward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairForward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesForward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }else if(GlobalObjects.playerSpriteImageAlternater == 6){
        g2d.drawImage(unitBodyForward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairForward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesForward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }else if(GlobalObjects.playerSpriteImageAlternater == 7){
        g2d.drawImage(unitBodyLeftward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairLeftward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesLeftward1, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }else if(GlobalObjects.playerSpriteImageAlternater == 8){
        g2d.drawImage(unitBodyLeftward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitHairLeftward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        g2d.drawImage(unitClothesLeftward2, GlobalObjects.characterX, GlobalObjects.characterY,32,40, this);
        Toolkit.getDefaultToolkit().sync();
        g.dispose();
    }
}


public void actionPerformed(ActionEvent e) {
    repaint();  
}
4

0 に答える 0