Add draw sorting based on Y position

This commit is contained in:
2023-12-29 09:42:15 +01:00
parent 6e2c68cb70
commit e7a0f91c36
7 changed files with 47 additions and 55 deletions

View File

@@ -208,34 +208,6 @@ void entityUpdateAnimation(ecs_iter_t *it) {
}
}
static void render(ecs_iter_t *it) {
Position *p = ecs_field(it, Position, 1);
Size *s = ecs_field(it, Size, 2);
Rotation *r = ecs_field(it, Rotation, 3);
TextureRegion *t = ecs_field(it, TextureRegion, 4);
for (i32 i = 0; i < it->count; i++) {
Rectangle dst = {p[i].x, p[i].y, s[i].x, s[i].y};
Vector2 origin = {dst.width * 0.5f, dst.height * 0.5f};
Rectangle src = t[i].rec;
if (t[i].flipX) src.width *= -1.0f;
if (t[i].flipY) src.height *= -1.0f;
DrawTexturePro(t[i].texture, src, dst, origin, t[i].rotation, WHITE);
}
}
void renderTerrain(ecs_iter_t *it) {
render(it);
}
void renderBuildings(ecs_iter_t *it) {
render(it);
}
void renderEntities(ecs_iter_t *it) {
render(it);
}
void renderColliders(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
Size *size = ecs_field(it, Size, 2);