所以我有点陷入困境。继承人我的问题
我可以绘制一个图块,但如果我绘制一个播放器(它是一个JPanel),它会覆盖另一个JPanel(存储地图信息)
我想到这样做的一种方式是使用layeredPane并创建JPanels网格,也创建不同的图层(所以当一个单元在树下行走时,你看不到它们),但我不知道知道如何在每个方格之间创建平滑的动画。
我不知道如何使用布局管理器创建平滑的移动,但我不太了解布局管理器。一旦我解决了这个问题,我就可以开始使用地图编辑器了。
我正在编写这个RPG游戏以更好地了解Java,我不知道我应该提供什么代码,所以如果你想要更多的代码,我会提供它。
//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();
}