ASGE  3.2.0
Simple Game Framework in GL
ASGE::Tile Struct Reference

#include <Tile.hpp>

Collaboration diagram for ASGE::Tile:
[legend]

Public Attributes

std::array< float, 4 > src_rect { 0, 0, 1, 1 }
 
ASGE::Colour tint { ASGE::COLOURS::WHITE }
 
ASGE::Texture2Dtexture { nullptr }
 
float rotation { 0.0F }
 
float opacity { 1.0F }
 
int width { 32 }
 
int height { 32 }
 
int16_t z { 0 }
 

Detailed Description

An ASGE supported tile.

Tiles, whilst sharing much of the same functionality as the ASGE::Sprite are conceptually quite different. Instead they are used to build more complex scenes and game maps. Because of this their position is normally dictated by the map itself and typically consists of using rows, columns and tile sizes to determine their exact positioning.

The aim of this struct is to easily allow this kind of functionality to exist within ASGE. Now instead of having to construct instances of Sprites with their own positional data, you can use a Tile instead.

When rendering a Tile you will need to provide the XY position that it's to appear in World Space. Remember that by default origins in ASGE for positions (not rotations) are calculated from the top-left.

Mozilla's developer documentation (https://developer.mozilla.org/en-US/docs/Games/Techniques/Tilemaps) does a great job of introducing tile maps and how conceptually they operate. This might help if you're unsure about when you would use a Tile instead of a Sprite.

Mozilla Developer Docs

Example:

// create a tile with a texture and source rectangle
auto& tile = tiles.emplace_back();
tile.texture = renderer->createCachedTexture("/data/img/tile_sheet.png");
tile.width = 64
tile.height = 64
tile.src_rect = {0, 0, 64, 64};
// assuming a 2D array
for (int row=0; row < map.length; ++row) {
for (int col=0; col < map.length; ++col) {
renderer->render(tiles[row][col],
ASGE::Point2D{col * map.tile_width, row * map.tile_height});
}
}
A point in 2D space.
Definition: Point2D.hpp:31

Definition at line 70 of file Tile.hpp.

Member Data Documentation

◆ height

int ASGE::Tile::height { 32 }

Height. How tall to render the tile.

Definition at line 78 of file Tile.hpp.

◆ opacity

float ASGE::Tile::opacity { 1.0F }

Opacity. Controls the alpha channel i.e. transparency.

Definition at line 76 of file Tile.hpp.

◆ rotation

float ASGE::Tile::rotation { 0.0F }

Rotation. Rotation to apply in radians.

Definition at line 75 of file Tile.hpp.

◆ src_rect

std::array<float, 4> ASGE::Tile::src_rect { 0, 0, 1, 1 }

Source Rectangle. The source rectangle used for sampling.

Definition at line 72 of file Tile.hpp.

◆ texture

ASGE::Texture2D* ASGE::Tile::texture { nullptr }

Texture. The source rectangle used for sampling.

Definition at line 74 of file Tile.hpp.

◆ tint

ASGE::Colour ASGE::Tile::tint { ASGE::COLOURS::WHITE }

Tint. Used to tint the colour of the tile.

Definition at line 73 of file Tile.hpp.

◆ width

int ASGE::Tile::width { 32 }

Width. How wide to render the tile.

Definition at line 77 of file Tile.hpp.

◆ z

int16_t ASGE::Tile::z { 0 }

Z. The rendering order to apply to the tile.

Definition at line 79 of file Tile.hpp.


The documentation for this struct was generated from the following file: