gamnit :: TileSet :: defaultinit
gamnit :: TileSet :: subtextures=
Cache of the subtextures of tilescore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
gamnit :: TileSet :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).gamnit :: TileSet :: subtextures=
Cache of the subtextures of tiles
# Efficiently retrieve tiles in a big texture
class TileSet
# Texture containing the tileset
var texture: Texture
# Width of a tile
var width: Numeric
# Height of a tile
var height: Numeric
# Number of columns of tiles in the texture
var nb_cols: Int = (texture.width / width.to_f).to_i is lazy
# Number of rows of tiles in the texture
var nb_rows: Int = (texture.height / height.to_f).to_i is lazy
# Cache of the subtextures of tiles
var subtextures: Array[Texture] is lazy do
var subtextures = new Array[Texture]
for j in [0..nb_rows[ do
for i in [0..nb_cols[ do
subtextures.add texture.subtexture(
i.to_f*width.to_f, j.to_f*height.to_f, width.to_f, height.to_f)
end
end
return subtextures
end
# Subtexture for the tile at `x, y`
#
# Require: `x < nb_cols and y < nb_rows`
fun [](x,y: Int): Texture
do
assert x >= 0 and x < nb_cols and y >= 0 and y <= nb_rows else print "{x}x{y}<?{nb_cols}x{nb_rows}"
var idx = x + y * nb_cols
return subtextures[idx]
end
end
lib/gamnit/tileset.nit:20,1--58,3