Skip to content

Missing way to get generated tiles from AutoLayer in integer coordinates #21

Open
@zommerfelds

Description

@zommerfelds

Issue

The Layer_Tiles has the useful function getTileStackAt() or hasAnyTileAt(). However, if you use an IntGrid or AutoLayer, there is no such way to get the tiles by integer coordinates. The only public value currently is:

public var autoTiles : Array<ldtk.Layer_AutoLayer.AutoTile>;

Which only exposes the pixel positions:

typedef AutoTile = {
/**
X coordinate to place this tile in your render
**/
var renderX: Int;
/**
Y coordinate to place this tile in your render
**/
var renderY: Int;

It would be nice to add getTileStackAt() or hasAnyTileAt() to the Layer_IntGrid_AutoLayer class.

Potential solutions

I'd propose to add a new variable which is a map, like it the Tiles layer:

var tiles : Map<Int, Array<{ tileId:Int, flipBits:Int }>>;

Then we can use coordinate IDs to find the right tile. The only problem here is that we'd be duplicating data with the autoTiles variable (changing it would be backwards incompatible since the variable is public). As an alternative 1 we can create a private Map<Int, Array<Int>> which just contains indices to the autoTiles variable. Or alternative 2 is to make the autoTitles a Haxe property with a getter function that is backed by the new variable. I think i prefer alternative 2.

What do you think? Happy to try to make a pull request with the preferred solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions