Tile

Anything placeable on the map is housed in a Tile.

A Tile can hold a TilePic or an Entity inside of it.

Note

When you use Entity::SetPos or Entity::SetBaseColor, internally, these functions are called.

The reason we use a Tile interface at times is that it lets us perform operations on an Entity or TilePic without knowing or caring what it really is.

Summary
TileAnything placeable on the map is housed in a Tile.
Member Functions
GetType
SetPos
GetPos
SetLayerID
GetLayerID
SetBaseColor
GetBaseColor
GetAsEntity
Tile Related Constants
C_TILE_TYPE_CONSTANTSUse with Tile::GetType to see what a Tile is actually housing inside.
C_TILE_TYPE_BLANKA blank/invalid tile.
C_TILE_TYPE_PICThis means the Tile houses a TilePic inside and <Tile::GetAsTilePic> is safe to use.
C_TILE_TYPE_ENTITYThis means the Tile houses an Entity inside and Tile::GetAsEntity is safe to use.

Member Functions

GetType

number GetType()

Returns

One of the C_TILE_TYPE_CONSTANTS.  If it is a C_TILE_TYPE_ENTITY, you know you can use the GetAsEntity function safely.

SetPos

nil SetPos(Vector2 vPos)

Parameters

vPosa Vector2 object containing the position to move to.

GetPos

Vector2 GetPos()

Returns

A Vector2 object containing the tile’s position.

SetLayerID

nil SetLayerID(number layerID)

Allows you to change the layer of an entity.

Note that the actual movement will not happen until the end of that game logic cycle.

Usage

this:SetLayerID(this:GetLayerID()+1); //move up one layer
//Note, this may or may not affect our sorting level as expected, depends on the layer's settings.

GetLayerID

number GetLayerID()

Usage

local layerID = this:GetLayerID();
LogMsg("We're on layer " .. layerID);

Returns

The layer ID that we’re on.

SetBaseColor

nil SetBaseColor(Color color);

Using this you can change the color of an entity/tilepic.  Technically, you’re just setting how much of red, green, blue can get through.

So if you start with white, you can make any color by removing the colors you don’t want.

A Color object also contains an alpha value, this lets you set the translucency.  (This happens on top of whatever per-pixel alpha the image already has)

Usage

myTile:SetBaseColor(Color(255,20,20,255)); //we should now look very red, since we're not
//letting much green or blue through.

//another example

Color c = Color(255,255,255,110); //full color, but only about half the alpha
myTile:SetBaseColor(c); //we're now about 50% invisible

Parameters

colorA Color object.

GetBaseColor

Color GetBaseColor();

Returns

A Color object containing the tile’s base color.

GetAsEntity

Entity GetAsEntity();

Returns

The Entity object interface inside the tile, or nil if this isn’t an entity.

Tile Related Constants

Summary
C_TILE_TYPE_CONSTANTSUse with Tile::GetType to see what a Tile is actually housing inside.
C_TILE_TYPE_BLANKA blank/invalid tile.
C_TILE_TYPE_PICThis means the Tile houses a TilePic inside and <Tile::GetAsTilePic> is safe to use.
C_TILE_TYPE_ENTITYThis means the Tile houses an Entity inside and Tile::GetAsEntity is safe to use.

C_TILE_TYPE_CONSTANTS

Use with Tile::GetType to see what a Tile is actually housing inside.

C_TILE_TYPE_BLANK

A blank/invalid tile.  Should never see this,

C_TILE_TYPE_PIC

This means the Tile houses a TilePic inside and <Tile::GetAsTilePic> is safe to use.

C_TILE_TYPE_ENTITY

This means the Tile houses an Entity inside and Tile::GetAsEntity is safe to use.

Anything placeable on the map is housed in a Tile.
TilePics are the simplest form of visual.
The Entity object.
Use with Tile::GetType to see what a Tile is actually housing inside.
This means the Tile houses an Entity inside and Tile::GetAsEntity is safe to use.
The Vector2 object.
The color object stores R G B A color information.