Skillpedia
برمجة عامة6.6k · #13830

godot-tilemap

ما الذي تفعله

تشرح هذه المهارة كيفية بناء مراحل ثنائية الأبعاد في Godot من شبكة بلاط، باستخدام TileMapLayer وTileSet. وهي مناسبة لصنّاع الألعاب الذين يبنون منصات أو خرائط من الأعلى أو مراحل مشابهة.

متى تستخدمها

  • ✓عندما تريد رسم مرحلة ثنائية الأبعاد من صور البلاط في Godot.
  • ✓عندما تحتاج إلى أن يكون للبلاط تصادم أو ملاحة أو قيم مخصصة مثل الضرر.
  • ✓عندما تريد نقل عقدة TileMap القديمة إلى إعداد TileMapLayer الأحدث.

رابط المهارة

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-tilemap/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-tilemap/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“ساعدني في رسم مرحلة منصات في Godot، حيث تؤذي الأشواك اللاعب عند لمسها.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تُظهر المهارة كيفية إعداد الطبقات ومجموعات البلاط، وإضافة التصادم والبيانات المخصصة للبلاط، واستخدام التضاريس لتتصل الحواف تلقائيًا، وقراءة البلاط أو تغييره من الكود.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Godot TileMap (4.7 TileMapLayer)

Author tile-based levels with TileMapLayer + TileSet, add per-tile collision and custom data, autotile with terrains, and manipulate cells at runtime. Targets Godot 4.7, where TileMapLayer replaces the now-deprecated TileMap node.

When to use

  • Use when designing 2D levels from a tile grid, configuring a TileSet (collision, navigation, custom data, terrains), or reading/writing tiles from code.
  • Use when migrating a TileMap node (single node, many layers) to multiple TileMapLayer nodes (one layer each).

When not to use: moving the player across the tiles → godot-2d-movement; general physics bodies/raycasts → godot-physics; procedural map generation algorithms → procedural-gen; level design practice → level-design.

Core workflow

  1. Add a TileMapLayer node (one per visual/logical layer: background, walls, foreground). Each holds exactly one layer of tiles.
  2. Create or assign a TileSet on the layer's tile_set property. Add an atlas source (a texture sliced into tiles) in the TileSet editor. Save the TileSet as an external .tres so multiple layers/levels reuse it.
  3. Add tile data in the TileSet editor: physics layers (collision polygons), navigation layers, occlusion, and custom data layers (typed per-tile values like damage or is_ladder).
  4. Paint in the TileMap bottom panel (Paint/Line/Rectangle/Bucket). For self- connecting tiles, define a terrain set and paint with Connect/Path mode.
  5. Enable per-layer collision/navigation via the layer's collision_enabled / navigation_enabled properties.
  6. Read/write from code with local_to_map, set_cell, get_cell_source_id, and get_cell_tile_data(...).get_custom_data(...).

Patterns

1. Convert mouse position to a cell and read its custom data

extends TileMapLayer

func _unhandled_input(event: InputEvent) -> void:
    if event is InputEventMouseButton and event.pressed:
        # event.position is in viewport pixels and ignores Camera2D scroll/zoom.
        # make_input_local() converts it into this layer's local space.
        var local_event := make_input_local(event) as InputEventMouseButton
        var cell := local_to_map(local_event.position)
        var data := get_cell_tile_data(cell)   # TileData or null
        if data:
            var dmg: int = data.get_custom_data("damage")  # custom data layer
            print("Cell %s deals %d damage" % [cell, dmg])

2. Place and erase tiles at runtime

# set_cell(coords, source_id, atlas_coords, alternative_tile = 0)
func place_wall(cell: Vector2i) -> void:
    set_cell(cell, 0, Vector2i(2, 1))   # source 0, atlas tile at column 2, row 1

func dig(cell: Vector2i) -> void:
    erase_cell(cell)                    # same as set_cell(cell, -1)

func clear_level() -> void:
    clear()                             # remove every tile on this layer

3. Autotiling a region with a terrain set

# Paint a filled area with terrain `terrain` of terrain set `terrain_set`;
# Godot picks the correct edge/corner tiles to connect them.
func fill_with_grass(cells: Array[Vector2i]) -> void:
    var terrain_set := 0
    var grass_terrain := 0
    set_cells_terrain_connect(cells, terrain_set, grass_terrain, true)

4. Iterate placed tiles (e.g. find all spawn tiles)

func find_spawns() -> Array[Vector2i]:
    var spawns: Array[Vector2i] = []
    for cell in get_used_cells():
        var data := get_cell_tile_data(cell)
        if data and data.get_custom_data("is_spawn"):
            spawns.append(cell)
    return spawns

Pitfalls

  • TileMap node is deprecated in 4.3. Use TileMapLayer nodes (one layer per node); group them under a parent Node2D. Old TileMap calls that took a layer argument (set_cell(layer, ...)) do not apply to TileMapLayer.
  • local_to_map needs layer-local coordinates. A world position needs to_local(...) first. A mouse event's position is in viewport pixels, not world space, so it is wrong as soon as a Camera2D scrolls or zooms; convert it with make_input_local(event) (or poll get_local_mouse_position()) instead.
  • get_cell_tile_data returns null for empty cells or non-atlas sources — always null-check before get_custom_data.
  • Custom data is typed. A layer declared as int returns int; reading it as the wrong type or
الأسئلة الشائعة

ما هو TileSet؟

هو مجموعة صور البلاط وإعداداتها التي تستخدمها طبقة البلاط.

ما هو الربط التلقائي؟

هو جعل الحواف بين أنواع البلاط تتصل تلقائيًا عند الرسم.

هل تغطي هذه المهارة تحريك اللاعب فوق البلاط؟

لا. تغطي حركة اللاعب مهارة منفصلة للحركة ثنائية الأبعاد.

التفاصيل

الوصف الأصلي من المؤلف

Build and edit tile-based 2D levels in Godot 4.7 with TileMapLayer and TileSet: paint layers, set up collision/navigation/custom-data on tiles, autotile with terrain sets, and read/write cells from code (set_cell, get_cell_tile_data, local_to_map). Use when working with TileMapLayer nodes, .tres TileSets, autotiling, or migrating a deprecated TileMap node to TileMapLayer.

repo: gamedev-skills/awesome-gamedev-agent-skills

الشعبية

نجوم GitHub
6.6k
الترتيب
#13830
الترخيص
Apache-2.0
آخر تحديث
28‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة