So, I’m trying to draw a tile set on the screen.
When I use a for loop, the tileset draws the lines correctly:
(ignore the tile on the middle, that’s a different draw)
This function is inside a Tile struct.
fn draw_set(tile: Tile, width: usize, height: usize) void {
var quad = tile;
for (0..width) |x| {
for (0..height) |z| {
quad.position = Vector3{
.x = @as(f32, @floatFromInt(x)) - (@as(f32, @floatFromInt(width)) / 2), // Centering the grid
.y = 0.0,
.z = @as(f32, @floatFromInt(z)) - (@as(f32, @floatFromInt(height)) / 2), // Centering the gridPreformatted text
};
Tile.draw(Tile.verts(quad.position, 2), tile.color, rl.Color.gold);
}
}
}
For Loop:
but when I try to use while loop, I get this:
fn draw_set(tile: Tile, width: i32, height: i32) void {
var x: i32 = 0;
var z: i32 = 0;
var quad = tile;
while (x <= width) : (x += 1) {
while (z <= height) : (z += 1) {
quad.position = Vector3{
.x = @as(f32, @floatFromInt(x)) - (@as(f32, @floatFromInt(width)) / 2), // Centering the grid
.y = 0.0,
.z = @as(f32, @floatFromInt(z)) - (@as(f32, @floatFromInt(height)) / 2), // Centering the grid
};
Tile.draw(Tile.verts(quad.position, 2), tile.color, rl.Color.gold);
}
}
}
While Loop:
I’m perfectly fine to use the for loop, but I just don’t understand, why it’s not working with the while loop, as I think they are doing the same.
I don’t think that the problem is here, but here is the draw()
function:
fn draw(vertices: [4]Vector3, color: rl.Color, color_line: rl.Color) void {
rl.drawTriangleStrip3D(&vertices, color);
rl.drawLine3D(vertices[0], vertices[1], color_line);
rl.drawLine3D(vertices[0], vertices[2], color_line);
rl.drawLine3D(vertices[2], vertices[3], color_line);
rl.drawLine3D(vertices[3], vertices[1], color_line);
}