Documentation
¶
Index ¶
- Constants
- Variables
- func EmitTilemapCommands(layer *Layer, commands *[]render.RenderCommand, viewTransform [6]float64, ...)
- func SetTileUVs(verts []ebiten.Vertex, region types.TextureRegion, flags uint32, ...)
- type AnimFrame
- type CameraBoundsAdapter
- type EmitCommandsFn
- type Layer
- func (l *Layer) EnsureBuffer(cols, rows int)
- func (l *Layer) InvalidateBuffer()
- func (l *Layer) LateRebuildCheck()
- func (l *Layer) Node() *node.Node
- func (l *Layer) RebuildBuffer(startCol, startRow, bufCols, bufRows int)
- func (l *Layer) SetAnimations(anims map[uint32][]AnimFrame)
- func (l *Layer) SetData(data []uint32, w, h int)
- func (l *Layer) SetTile(col, row int, newGID uint32)
- type LayerConfig
- type Viewport
- type VisibleBoundsProvider
Constants ¶
const ( TileFlipH uint32 = 1 << 31 TileFlipV uint32 = 1 << 30 TileFlipD uint32 = 1 << 29 TileFlagMask uint32 = TileFlipH | TileFlipV | TileFlipD )
GID flag bits (same convention as Tiled TMX format).
const MaxTilesPerDraw = 16383
MaxTilesPerDraw is the maximum number of tiles per DrawTriangles call.
Variables ¶
var ( // NewContainerFn creates a container node. Set by root package. NewContainerFn func(name string) *node.Node // NewLayerEmitFn, if set, is called after AddTileLayer creates a Layer so // root can inject the render-command emission logic as Layer.EmitFn. NewLayerEmitFn func(layer *Layer) )
Function pointers wired by root to break dependency on Camera, Scene, etc.
var UVOrder = [8][4]int{
{0, 1, 2, 3},
{2, 0, 3, 1},
{2, 3, 0, 1},
{3, 2, 1, 0},
{1, 0, 3, 2},
{0, 2, 1, 3},
{3, 2, 1, 0},
{1, 3, 0, 2},
}
UVOrder defines vertex UV assignment for each combination of flip flags.
Functions ¶
func EmitTilemapCommands ¶
func EmitTilemapCommands(layer *Layer, commands *[]render.RenderCommand, viewTransform [6]float64, treeOrder *int)
EmitTilemapCommands transforms tile vertices into screen space and appends one or more CommandTilemap render commands (split at MaxTilesPerDraw) to the provided command slice. viewTransform is the camera's view matrix.
func SetTileUVs ¶
SetTileUVs sets the UV (SrcX/SrcY) coordinates for 4 vertices of a tile.
Types ¶
type AnimFrame ¶
type AnimFrame struct {
GID uint32 // tile GID for this frame (no flag bits)
Duration int // milliseconds
}
AnimFrame describes a single frame in a tile animation sequence.
type CameraBoundsAdapter ¶
CameraBoundsAdapter wraps *camera.Camera to satisfy VisibleBoundsProvider.
func (*CameraBoundsAdapter) ViewportHeight ¶
func (a *CameraBoundsAdapter) ViewportHeight() float64
func (*CameraBoundsAdapter) ViewportWidth ¶
func (a *CameraBoundsAdapter) ViewportWidth() float64
func (*CameraBoundsAdapter) VisibleBounds ¶
func (a *CameraBoundsAdapter) VisibleBounds() types.Rect
type EmitCommandsFn ¶
EmitCommandsFn is the callback type for emitting tilemap render commands. The any parameter is the opaque *Scene, matching Node.CustomEmit signature.
type Layer ¶
type Layer struct {
Node_ *node.Node
Data []uint32
Width int
Height int
Vertices []ebiten.Vertex
Indices []uint16
TileCount int
WorldX []float32
WorldY []float32
Regions []types.TextureRegion
BufStartCol int
BufStartRow int
BufCols int
BufRows int
BufDirty bool
Anims map[uint32][]AnimFrame
AtlasImage *ebiten.Image
Viewport_ *Viewport
// EmitFn is called during rendering to emit tilemap commands.
EmitFn EmitCommandsFn
}
Layer is a single layer of tile data.
func (*Layer) EnsureBuffer ¶
EnsureBuffer grows the geometry buffer if needed.
func (*Layer) InvalidateBuffer ¶
func (l *Layer) InvalidateBuffer()
InvalidateBuffer forces a full buffer rebuild on the next frame.
func (*Layer) LateRebuildCheck ¶
func (l *Layer) LateRebuildCheck()
LateRebuildCheck detects whether the camera moved after the Update pass.
func (*Layer) RebuildBuffer ¶
RebuildBuffer fills the vertex buffer with tile data for the given range.
func (*Layer) SetAnimations ¶
SetAnimations sets the animation definitions for this layer.
type LayerConfig ¶
type LayerConfig struct {
Name string
Width int
Height int
Data []uint32
Regions []types.TextureRegion
AtlasImage *ebiten.Image
}
LayerConfig holds the parameters for creating a tile layer.
type Viewport ¶
type Viewport struct {
TileWidth int
TileHeight int
MaxZoomOut float64
MarginTiles int
// CameraBoundsFn resolves the camera to a VisibleBoundsProvider.
CameraBoundsFn func(cam any) VisibleBoundsProvider
// contains filtered or unexported fields
}
Viewport is a scene graph node that manages a viewport into a tilemap.
func NewViewport ¶
NewViewport creates a new tilemap viewport node.
func (*Viewport) AddTileLayer ¶
func (v *Viewport) AddTileLayer(cfg LayerConfig) *Layer
AddTileLayer creates a tile layer and adds it as a child of the viewport.
func (*Viewport) UpdateAnimations ¶
func (v *Viewport) UpdateAnimations()
UpdateAnimations scans layers for animated tiles and updates their UVs.