struct Prism::TextureAtlas

Defined in:

prism/texture/texture_atlas.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(size : UInt32) #

Produces an atlas for retrieving texture coordinates.

The size determins the number of columns and rows in the atlas.

Example

A size of 4 will produces a 4x4 atlas. Coordinates for each texture in the atlas will be retrievable by the index number.

+---------------+ | 0 | 1 | 2 | 3 | |---|---|---|---| | 4 | 5 | 6 | 7 | |---|---|---|---| | 8 | 9 | 10| 11| |---|---|---|---| | 12| 13| 14| 15| +---------------+


[View source]
def self.new #

Creates an atlas with a default size of 1. This will produces coordinates for a regular texture that is not an atlas.


[View source]

Instance Method Detail

def get_coords(col : UInt32, row : UInt32) : TextureCoords #

Returns the coordinates for index at the given col and row in the atlas.


[View source]
def get_coords(index : UInt32) : TextureCoords #

Returns the coordinates for an index in the atlas.

Example

Given a 4x4 grid like this one:

+---------------+ | 0 | 1 | 2 | 3 | |---|---|---|---| | 4 | 5 | 6 | 7 | |---|---|---|---| | 8 | 9 | 10| 11| |---|---|---|---| | 12| 13| 14| 15| +---------------+

We can fetch the coordinates at index 9:

texture_atlas.get_coordinates(9) # => { col: 1, row: 2}

[View source]
def size : UInt32 #

[View source]