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.
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.
Variables
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 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.
read onlyy:Float
Vertical position of the Tile on the Texture.
Cannot be modified directly, use Tile.setPosition
instead.
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
.
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.
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]
.
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.
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.
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.
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. |
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:
|
---|