fix: Флип тайлов перенесен в рендер

This commit is contained in:
2026-08-28 20:17:36 +05:00
parent 35a64fe432
commit cdadd72635
2 changed files with 27 additions and 18 deletions
+11 -8
View File
@@ -76,7 +76,7 @@ draw_scene :: proc(scene: ^Scene) {
0,
0,
cast(f32)scene.map_tex.texture.width,
-cast(f32)scene.map_tex.texture.height, // FIX: flip Y axis
cast(f32)scene.map_tex.texture.height,
},
rl.Rectangle {
0,
@@ -112,10 +112,16 @@ draw_scene :: proc(scene: ^Scene) {
}
render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D {
tex := rl.LoadRenderTexture(map_data.width * 16, map_data.height * 16)
tex := rl.LoadRenderTexture(
map_data.width * i32(atlas.tile_size.x),
map_data.height * i32(atlas.tile_size.y),
)
// RT хранится в GL-координатах (Y вверх), поэтому ряды тайлов пишем
// снизу вверх — тогда текстуру можно выводить без переворота
rl.BeginTextureMode(tex)
for layer in map_data.layers {
for row_data, row in layer.data {
dest_y := f32(i32(map_data.height) - 1 - i32(row)) * atlas.tile_size.y
for tile_id, col in row_data {
offset, empty := get_offset(atlas, tile_id)
if empty do continue
@@ -125,11 +131,11 @@ render_map :: proc(atlas: ^Atlas, map_data: Map) -> rl.RenderTexture2D {
offset.x,
offset.y,
atlas.tile_size.x,
atlas.tile_size.y,
-atlas.tile_size.y, // флип: RT хранит квадры перевёрнутыми
},
rl.Rectangle {
f32(col) * atlas.tile_size.x,
f32(row) * atlas.tile_size.y,
dest_y,
atlas.tile_size.x,
atlas.tile_size.y,
},
@@ -175,10 +181,7 @@ main :: proc() {
arena_alloc := runtime.arena_allocator(&arena)
map_data, err := load_map(
"./Tiled/map_file.json",
arena_alloc,
)
map_data, err := load_map("./Tiled/map_file.json", arena_alloc)
if err.type != .None {
fmt.println(err.msg)