Hi there,
I was coding today some constructions, but the problem I saw was that the constructions were overlapping each other. So I thaught let’s make a simple forloop that look for the first y and then draws it.
public void renderEntities(Screen screen) {
for (Entity e : getEntities()) {
for (int yDraw = 0; yDraw < this.height; yDraw++){
int yPlace = e.getY();
if(yPlace == yDraw){
e.render(screen);
}
}
}
}
The idea was simple, but afterwards I checked what I did and I thaught: What am I doing? So I looked at my code again and started to think at what was first the code:
public void renderEntities(Screen screen) {
for (Entity e : getEntities()) {
e.render(screen);
}
}
This code is evrytime taking the first entity in the list (then the second etc.), so why was I looking for the first entity’s y? then ++ it, this will make entities that are later in the list and have a higher y invisible. But I don’t know how to search wich Y is first and then using that entity first, does anyone know how this works good and can explain me how it works? Because I need to learn how to programm and I want to solve the problem!
Already thanks!
-RoseSlayer