Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drawing limits and terrain boundary behavior to TileMapLayer #11240

Open
nuevocharrua opened this issue Nov 27, 2024 · 2 comments
Open

Add drawing limits and terrain boundary behavior to TileMapLayer #11240

nuevocharrua opened this issue Nov 27, 2024 · 2 comments
Labels

Comments

@nuevocharrua
Copy link

Describe the project you are working on

I am developing a 2D tile-based game where precise control over where tiles can be placed is crucial. The current TileMap system allows drawing tiles anywhere, which can lead to issues when designing levels with specific boundaries or when implementing terrain-based game mechanics that need to consider area limits as terrain boundaries (similar to GameMaker's implementation).

Describe the problem or limitation you are having in your project

Currently, the TileMapLayer in Godot 4.3 lacks the ability to:

  • Set specific boundaries where tiles can be drawn/placed
  • Consider these boundaries as terrain when using terrain tools
  • Prevent tile placement outside designated areas

This limitation makes it difficult to:

  • Create levels with strict boundaries
  • Implement terrain-aware tile placement near boundaries
  • Prevent accidental tile placement outside intended areas
  • Create tools that respect level boundaries automatically

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a new feature to TileMapLayer that allows:

  • Setting a rectangular boundary (Rect2i) that defines where tiles can be placed
  • An option to treat the boundary as terrain, making the tilemap consider cells outside the boundary as "occupied" for terrain matching
  • Automatic terrain matching when placing tiles near boundaries (when enabled)

This would provide better control over level design and improve the terrain system's behavior near boundaries.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams


void TileMapLayer::set_cell(const Vector2i &p_coords, ...) {
    if (!draw_limits.has_point(p_coords)) {
        return; // Don't allow placing tiles outside limits
    }
    
    if (consider_limits_as_terrain) {
        // Check if we're at boundary
        // Apply terrain matching considering boundary
        // ...
    }
    
    // Continue with normal tile placement
}

If this enhancement will not be used often, can it be worked around with a few lines of script?

While this could be partially worked around with scripts, it would require:

  • Constant checking of coordinates before placing tiles
  • Complex custom terrain matching logic
  • Manual handling of boundary conditions
  • Additional overhead for every tile placement operation

A script-based solution would be less efficient and more error-prone than a native implementation.

Is there a reason why this should be core and not an add-on in the asset library?

This feature should be part of the core engine because:

  • It extends fundamental TileMap functionality used by many games
  • It requires deep integration with the existing terrain system
  • Performance is critical for tile operations
  • It would ensure consistent behavior across all tools and scripts using TileMap
  • The feature would benefit from being maintained alongside the core TileMap code
@Mickeon
Copy link

Mickeon commented Nov 27, 2024

It's reasonably possible to code this manually with the new _update_cells() virtual method:

@nuevocharrua
Copy link
Author

It's reasonably possible to code this manually with the new _update_cells() virtual method:

Grid limiting is definitely possible, considering the limit as "occupied" and applying terrain rules might be a bit more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants