Skip to content

How to access tile data? #10

@TLINDEN

Description

@TLINDEN

Hi,

this is possibly a dumb question, but I'm not getting it yet :) Let's say I define grid this way:

type Cell struct {
	sprite string
}

grid := tile.NewGridOf[Cell](width, height)

When iterating over the grid, like this:

grid.Each(func(point tile.Point, t tile.Tile[Cell]) {
  // t.Value() returns an int16 which is 0 in all tiles, no Cell ???
})

Of course I can create another map of cells like this:

cells := make(map[tile.Point]Cell, width*height)
grid.Each(func(point tile.Point, t tile.Tile[Cell]) {
  cells[point] = &Cell{"...."}
})

But that way I'd have two grids, the one provided by the tile module and my "shadow" grid holding the cell data (where I'd put things like sprites, properties etc).

What am I doing wrong?

Thanks in advance,
Tom

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