texcoord
v1.0.2
Published
uv texture coordinates from a region
Maintainers
Readme
texcoord
Get a [u1, v1, u2, v2] texture coordinate region from the given bounds. Best suited for rendering with top left texture coordinates.
//sprite bounds
var position = [0, 0]
var size = [64, 64]
//atlas dimensions
var atlasSize = [1024, 1024]
var t = texcoord(position, size, atlasSize)
// [ 0, 0, 0.0625, 0.0625 ]
var def = texcoord()
// [0, 0, 1, 1]Usage
texcoord([position, shape, texShape, out])
Returns a [u1, v1, u2, v2] array with texture coordinates (typically 0.0 to 1.0) based on the given regions. All arguments are optional.
positionsthe [x,y] position for our spriteshapethe [width,height] sprite sizetexShapethe [width,height] for our atlas (defaults to sprite size)outif specified, the result will be stored in this array rather than creating a new one
If no arguments are specified, the return will be [0, 0, 1, 1] (i.e. "use full atlas").
License
MIT, see LICENSE.md for details.

