A core 2D rendering component representing a region of an underlying h3d.mat.Texture.

Tiles cannot be created directly, and instances are created with the following methods: Via the Resource Management system: hxd.res.Image.toTile. From pre-existing Texture: Tile.fromTexture. From pre-existing BitmapData or Pixels: Tile.fromBitmap and Tile.fromPixels (as well as Tile.autoCut). From solid color: Tile.fromColor. * From previously existing Tile instance via various methods, such as Tile.sub.

Static methods

staticautoCut(bmp:BitmapData, width:Int, ?height:Int):{tiles:Array<Array<Tile>>, main:Tile}

Creates a new POT Texture from bmp and cuts it in a grid of tiles with maximum size of [width, height].

Algorithm will use bottom-right pixels as background color and cut out empty space from each Tile and will modify the origin point to retain the Tile position. Each row scan continues as long as there are no empty tiles.

Parameters:

bmp

The BitmapData which will be split into tiles.

width

The width of a single grid entry.

height

An optional height of a single grid entry. Width will be used if not provided.

staticfromBitmap(bmp:BitmapData):Tile

Creates a new Texture from provided BitmapData and returns a Tile representing it.

@:value({ alpha : 1., height : 1, width : 1 })staticfromColor(color:Int, width:Int = 1, height:Int = 1, alpha:Float = 1.):Tile

Create a solid color Tile with specified width, height, color and alpha.

Parameters:

color

The RGB color of the Tile.

width

The width of the Tile in pixels.

height

The height of the Tile in pixels.

alpha

The transparency of the Tile.

staticfromPixels(pixels:Pixels):Tile

Creates new POT Texture from Pixels and returns a Tile representing it.

staticfromTexture(t:Texture):Tile

Create new Tile from provided Texture instance.

Variables

dx:Float

Visual offset of the Tile along the X axis during rendering.

dy:Float

Visual offset of the Tile along the Y axis during rendering.

read onlyheight:Float

Height of the Tile. Not guaranteed to represent real height of the Tile on texture. (see Tile.scaleToSize)

Cannot be modified directly, use Tile.setSize instead.

read onlyiheight:Int

An integer height of the Tile. Alias to Math.ceil(tile.height + tile.y) - tile.iy.

read onlyiwidth:Int

An integer width of the Tile. Alias to Math.ceil(tile.width + tile.x) - tile.ix.

read onlyix:Int

An integer horizontal position of the Tile on the Texture. Alias to Math.floor(tile.x).

read onlyiy:Int

An integer vertical position of the Tile on the Texture. Alias to Math.floor(tile.y).

read onlywidth:Float

Width of the Tile. Not guaranteed to represent real width of the Tile on texture. (see Tile.scaleToSize)

Cannot be modified directly, use Tile.setSize instead.

read onlyx:Float

Horizontal position of the Tile on the Texture.

Cannot be modified directly, use Tile.setPosition instead.

xFlip:Bool

The flip state of the Tile.

See also:

read onlyy:Float

Vertical position of the Tile on the Texture.

Cannot be modified directly, use Tile.setPosition instead.

yFlip:Bool

The flip state of the Tile.

See also:

Methods

center():Tile

Returns a new Tile with shifting origin point (dx and dy) to the tile center.

To modify this Tile origin point, use Tile.setCenterRatio.

clone():Tile

Create a copy of this Tile instance.

dispose():Void

Disposes of the Tile and its underlying Texture. Note that if Texture is used by other Tile instances, it will cause them to point at a disposed texture and can lead to errors.

flipX():Void

Flips the Tile horizontally. Note that dx is flipped as well.

flipY():Void

Flips the Tile vertically. Note that dy is flipped as well.

inlinegetTexture():Texture

Returns an underlying Texture instance.

@:value({ dy : 0., dx : 0. })grid(size:Float, dx:Float = 0., dy:Float = 0.):Array<Array<Tile>>

Split the tile into a list of tiles of Size x Size pixels.

Parameters:

size

The width and height of the new Tiles.

dx

Optional visual offset of the new Tiles along the X axis.

dy

Optional visual offset of the new Tiles along the Y axis.

Returns:

A two-dimensional array ordered in [X][Y].

@:value({ dy : 0., dx : 0. })gridFlatten(size:Float, dx:Float = 0., dy:Float = 0.):Array<Tile>

Split the tile into a list of tiles of Size x Size pixels.

Parameters:

size

The width and height of the new Tiles.

dx

Optional visual offset of the new Tiles along the X axis.

dy

Optional visual offset of the new Tiles along the Y axis.

Returns:

A one-dimensional array ordered in Y/X.

isDisposed():Bool

Checks if Tile or underlying Texture were disposed.

scaleToSize(w:Float, h:Float):Void

Rescales the Tile to be of the set width and height, but without affecting the uv coordinates.

Using this method allows to upscale/downscale Tiles, but creates a mismatch between the tile uv and width/height values. Due to that, using any methods that modify the uv value will cause the new uv to treat scaled width and height as true dimensions and can lead to unexpected results if not accounted for.

scrollDiscrete(dx:Float, dy:Float):Void

Scrolls the texture position by specified amount.

@:value({ py : 0.5, px : 0.5 })inlinesetCenterRatio(px:Float = 0.5, py:Float = 0.5):Void

Sets dx / dy as origin point dictated by px / py with a default being center.

setPosition(x:Float, y:Float):Void

Set the Tile position in the texture to the specified coordinate.

setSize(w:Float, h:Float):Void

Set the Tile size in the texture to the specified dimensions.

@:value({ subpixel : false, vertical : false, frames : 0 })split(frames:Int = 0, vertical:Bool = false, subpixel:Bool = false):Array<Tile>

Split the Tile horizontally or vertically by the number of given frames.

Parameters:

frames

The amount of frames this Tile has to be split into.

vertical

Causes split to be done vertically instead of horizontal split.

subpixel

When enabled, retains the floating-point remainder if calculated frame size is not integral.

@:value({ dy : 0., dx : 0. })sub(x:Float, y:Float, w:Float, h:Float, dx:Float = 0., dy:Float = 0.):Tile

Create a sub-region of this Tile with specified size and offset.

Parameters:

x

The offset on top of the current Tile offset along the X axis.

y

The offset on top of the current Tile offset along the Y axis.

w

The width of the new Tile region. Can exceed current tile size.

h

The height of the new Tile region. Can exceed the current tile size.

dx

An optional visual offset of the new Tile along the X axis.

dy

An optional visual offset of the new Tile along the Y axis.

inlineswitchTexture(t:Tile):Void

Changes this Tile underlying texture to one used in the specified Tile.

If Tile was scaled, new uv will cover new width and height instead of the original unscaled one.

@:privateAccess tile.setTexture(myTextureInstance);

Parameters:

t

The Tile used as a source of the Texture instance. It's possible to switch texture by referring the Texture instance directly, by using access hacks: