Skip to content

graphics.tileset.wren

clsource edited this page Nov 15, 2020 · 4 revisions

Tileset

A simple tileset builder. Some code based on Ogmo Lib.

  • Example:
import "domepunk/graphics/tileset" for Tileset

// Load a tileset of 16x16 px squares
var size = 16
var tileset = Tileset.load("tiles.png", size)
tileset.offset(30, 30)

// draw each tile horizontally
var index = 0
for (tile in tileset.tiles) {
  tile.draw(size * index, 0)
  index = index + 1
}
  • Since: 1.0.0

API

The source image of the tileset

  • Signature: image: ImageData

The width of the tileset

  • Signature: width : Num

The height of the tileset

  • Signature: height : Num

The x offset of the tileset

  • Signature: x : Num

The y offset of the tileset

  • Signature: y : Num

The x,y offset of the tileset

  • Signature: offset : Point

The list of tiles.

  • Signature: tiles : [Tile]

The number of tiles inside tileset

  • Signature: count : Num

Default width and height

  • Signature: defaultSize : Num = 8

Creates a new tileset giving an image path.

  • Signature: static load(path:String, x:Num? = 0, y:Num? = 0, width:Num? = 8, height:Num? = 8)
  • Parameter path: The path to the image.
  • Parameter x: optional The x offset for the tileset.
  • Parameter y: optional The y offset for the tileset.
  • Parameter width: optional The width for each tileset.
  • Parameter height: optional The height for each tileset.
  • Return: a new Tileset instance.

No offset. Just path, width and height.

No offset. Will use size as width and height

Use only default values.


A tile instance inside the tileset.tiles list

API

The tileset where this tile is member of

  • Signature: tileset : Tileset

The source image of this tile

  • Signature: image: ImageData

x position inside the tileset

  • Signature: x : Num

y position inside the tileset

  • Signature: y : Num

width of this tile

  • Signature: width: Num

height of this tile

  • Signature: height: Num

Index of the tile inside tileset

  • Signature: index: Num

Draws the tile using ImageData.drawArea. It would consider the offset in the tileset.

  • Signature: draw(x:Num, y:Num) -> Void