У меня есть небольшая проблема при отображении изометрических плиток в моей школьной игре.
Факт, я полагаю, что с моим кодом все в порядке ... < /p>
Вот как это организовано: < /p>
Архитектура: MVC + ECS < /li>
everliefure rue -leprew. /> Я использую базы и ветера, чтобы сделать преобразования между двумя основаниями (ортогональный и изометрический) < /li>
< /ul>
Вот код: < /p>
public void render() {
try {
final Entity[] entities = this.controller.getEntities();
// Sort entities by isometric depth
Arrays.sort(entities, (e1, e2) -> {
PositionComponent p1 = e1.getComponent(PositionComponent.class);
PositionComponent p2 = e2.getComponent(PositionComponent.class);
// Calculate depth as the sum of cartesian x + y
double depth1 = p1.getX() + p1.getY();
double depth2 = p2.getX() + p2.getY();
// Primary sorting criterion: depth
int result = Double.compare(depth1, depth2);
// Secondary sorting: cartesian Y coordinate
if (result == 0) {
result = Double.compare(p1.getY(), p2.getY());
}
// Tertiary sorting: cartesian X coordinate
if (result == 0) {
result = Double.compare(p1.getX(), p2.getX());
}
// Fallback sorting: hashCode
if (result == 0) {
result = Integer.compare(e1.hashCode(), e2.hashCode());
}
return result;
});
for (Entity entity : entities) {
// Get position component
PositionComponent position = entity.getComponent(PositionComponent.class);
// Convert to isometric coordinates
Vector isoPos = this.gameBase.mulByVect(
new Vector2D(position.getX(), position.getY())
);
// Debug: print isometric position
// System.out.println("Isometric Position: " + isoPos);
// Get texture component
ImageIcon image = entity.getComponent(TextureComponent.class).getTexture();
// Create label for the entity
JLabel label = new JLabel(image);
// Set bounds based on isometric position
label.setBounds(
(int) isoPos.getEntry(0),
(int) isoPos.getEntry(1),
image.getIconWidth(),
image.getIconHeight()
);
this.panel.add(label);
}
// Revalidate and repaint after adding all entities
this.panel.revalidate();
this.panel.repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
< /code>
Однако плитки плохо отображаются. На самом деле самый дальний отображается после ближайшего, поэтому он кажется перевернутым ...
У вас есть идеи?
Подробнее здесь: https://stackoverflow.com/questions/792 ... tric-tiles