Multiple images data container that can be packed into a single texture. Use it to avoid the usage of multiple textures.

Give it datas using the appropriate addX functions then use the make function to generate the texture.

All the useful datas of an image are contained in SubData instances.

Available since

0.1.0

.

Constructor

new()

Creates an Atlas instance.

In debug mode, the instance will be aware of any file change. By default, if a file associated with the instance changes, the instance will update itself and call its onHotReload function.

Variables

@:value(null)read onlybytes:Bytes = null

Bytes of the generated texture.

@:value(0)read onlyheight:Int = 0

Height of the generated texture.

@:value([])listeningObjects:Array<{onHotReload:() ‑> Void, o:Object}> = []

@:value(true)makePOT:Bool = true

If true, the next texture generated will have its width and height be a power of two. This is good for GPUs.

@:value("")name:String = ""

The name of this instance. Can be locked when created for internal usage.

@:value(null)read onlypixels:Pixels = null

The hxd.Pixels generated to make the texture.

@:value(false)preventTextureAutoDispose:Bool = false

If true, old texture will be disposed when a new one is generated.

@:value(true)remakeAtlasOnFileChange:Bool = true

When false, this instance is prevented from doing anything when a file changes.

@:value([])read onlysubDatas:Array<SubData> = []

The SubDatas used to generate the texture.

@:value(null)read onlytexture:Texture = null

The generated texture.

@:value(0)read onlywidth:Int = 0

Width of the generated texture.

Methods

@:value({ toFormat : RGBA })addAseprite(aseprite:Ase, ?name:String, toFormat:PixelFormat = RGBA):Array<SubData>

Retrieve datas from an nb.Ase's instance and returns the SubData instance(s) made from it.

Parameters:

aseprite

The nb.Ase instance to make the SubData instance(s) from.

name

A string used to make the SubData instance(s) name from. A SubData instance's name will have a name in this format : [name]_[frame]:[layer].

toFormat

The pixel format to convert the bytes of aseprite to before using it to make the SubData instance(s).

Returns:

An array of the SubData instance(s) made.

@:value({ format : PixelFormat.RGBA })inlineaddBytes(bytes:Bytes, w:Int, h:Int, name:String, format:PixelFormat = PixelFormat.RGBA, ?toFormat:PixelFormat):SubData

Makes a SubData instance from the parameters and returns it.

Parameters:

bytes

haxe.io.Bytes of the image to make the SubData instance with.

w

Width of the image.

h

Height of the image.

name

A name to assign to the SubData instance.

format

Pixel format of bytes.

toFormat

Pixel format to convert bytes to before using it to make the SubData instance.

Returns:

The SubData instance made.

addImage(image:Image, ?name:String, ?toFormat:PixelFormat, ?flipY:Bool, ?index:Int):SubData

Retrieve datas from an hxd.Res.Image's instance and returns the SubData instance made from it.

Parameters:

image

The hxd.Res.Image instance to make the SubData instance from.

name

A name to assign to the SubData instance. Defaults to image's name.

toFormat

The pixel format to convert the bytes of image to before using it to make the SubData instance.

flipY

Set to true if image needs to be flipped vertically.

index

Index used to read image data from a Dds file.

Returns:

The SubData instance made.

addPixels(pixels:Pixels, name:String, ?toFormat:PixelFormat):SubData

Retrieve datas from an hxd.Pixels's instance and returns the SubData instance made from it.

Parameters:

pixels

The hxd.Pixels instance to make the SubData instance from.

name

The name to assign to the SubData instance.

toFormat

The pixel format to convert the bytes of pixels to before using it to make the SubData instance.

Returns:

The SubData instance made.

getSubData(name:String):SubData

Returns a SubData instance with the same name.

@:value({ format : PixelFormat.RGBA, maxH : 2048, maxW : 2048 })make(maxW:Int = 2048, maxH:Int = 2048, format:PixelFormat = PixelFormat.RGBA):Void

Generates a texture using the SubData instances.

Parameters:

maxW

Max width of the generated texture. If not a power of two and makePOT is true, the max width will be the power of two just after maxW.

maxH

Max height of the generated texture. If not a power of two and makePOT is true, the max height will be the power of two just after maxH.

format

Desired pixel format of pixels and the generated texture.

onHotReload():Void

Called after a new texture was generated from file change.

Calls the onHotReload function of all objects in listeningObjects.

inlineremake():Void

Same as make() but uses the last parameters that were given to it.

removeSubData(name:String):Bool

Removes a SubData instance from the collection with the same name. Returns true if one was removed, false otherwise.

inlinetoTile():Tile

Makes a new h2d.Tile instance from the generated texture then returns it.