Most of these map settings are also available in the editor under Map Properties.
If the map is saved (by defaults maps auto-save and are persistent), changes made are remembered.
A game may have an unlimited number of maps.
Each map contains its own LayerManager which can be accessed to see what kind of layers it has.
|Map||A map is a single area that can be any size and contain any amount of tiles, including Entities and TilePic’s.|
|C_RAY_CONSTANTS||Used with Map::GetCollisionByRay.|
|C_RAY_ENTITIES||The ray will hit only entities.|
|C_RAY_TILE_PIC||The ray will hit only tile pics.|
|C_RAY_EVERYTHING||The ray will hit entities as well as tile pics.|
|C_RAY_DEBUG||The rays will be visually drawn on the screen, helps to figure out problems.|
nil SetPersistent(boolean bPersistent)
By default, maps are persistent, meaning all changes are remembered and automatically saved in the player’s profile. (the original is not changed, only the player’s modified version of it)
This only has meaning when a player profile is active.
|bPersistant||True if the map should be persistent and changes remembered, false if not|
True if the map is persistent and changes will be remembered on a per-player-profile basis.
nil SetAutoSave(boolean bAutoSave)
This only applies when a user profile is not yet loaded.
For title screens, auto-save is usually turned off because no player profile is loaded, yet we don’t want to save after we mess up the screen.
|bAutoSave||True if the map should automatically be saved without needing to choose “Save map now” from the editor.|
The exact size of the map in world coordinates, based on visual data. Will be computed the first time it is needed. If chunks of the map are erased, you must call ComputeWorldRect yourself if you want this to be updated.
a Rectf containing the location of the used map.
nil SetWorldRect(Rectf viewArea)
Allows you to manually set the map view rect, allowing more control when the camera is setup to respect these boundries.
|viewArea||a Rectf object containing the boundries of this map in world coordinates.|
Rect ComputeWorldRect(number reserved)
Computes the actual size of the entire map in world coordinates by looking at the size of each entity/tile. Slow. GetWorldRect will now return this cached data.
|reserved||Reserved for future features, you must always pass it 0.|
a Rect containing the location of the used map.
This map’s LayerManager, containing all information about its layers and layer settings.
Rebuilds the navigational graph for this map.
In general, this isn’t needed, as navigational graphs are grown/destroyed fluidly on the fly as the map changes.
Zone GetCollisionByRay(Vector2 vStartPos, Vector2 vDir, number rayRange, number raySpread,
Entity entToIgnore, number mode, boolean bIgnoreCreatures)
Allows you to shoot a ray from any point in this map and see what it hits.
The returned Zone object’s vPos member will contain the exact position of the hit, its other values will contain additional information about the collision.
//let's shoot a ray in front of this entity and see if it detects any other entities)
local rayRange = 80;
local raySpread = 8; //causes 5 rays to be shot in a spread formation 8 units apart, easier to detect hits. 0 to use
//1 ray only
local entToIgnore = this;
local hitZone = this:GetMap():GetCollisionByRay(this:GetPos(), this:GetVectorFacing(), rayRange, raySpread,
entToIgnore, C_RAY_ENTITIES, false);
if (hitZone.entityID != C_ENTITY_NONE) then
//we have an entity in front of us!
local ent = GetEntityByID(hitZone.entityID);
LogMsg("Entity " .. tostring(ent) .. " is sitting in front of us.");
|vStartPos||A Vector2 object containing the start position of the ray.|
|vDir||A unit vector containing the direction of the ray.|
|rayRange||How far the ray can reach.|
|raySpread||0 for a single ray, otherwise will shoot five rays in a spread formation, this distance apart from each one.|
|entToIgnore||An Entity we should ignore during the check, otherwise nil|
|mode||One of the C_RAY_CONSTANTS. Use C_RAY_DEBUG to visually see the rays being shot.|
|bIgnoreCreature||If true, creatures are ignored during the check.|
TileList GetTilesByRect(Rect rect, LayerList layers, boolean bWithCollisionOnly)
This allows you to grab a list of all the entities and tiles in a rectangular area of the map.
You can later cycle through the list examining each one, or move or copy the list to a new place. (well, the moving/pasting as a group isn’t accessible yet in script, coming soon?)
//grab all tiles/entities we're touching
local layerList = this:GetMap():GetLayerManager():GetVisibleLayers(); //what layers we'll scan
local tileList = this:GetMap():GetTilesByRect( Rect(this:GetWorldCollisionRect()), layerList, false); //grab them
LogMsg("Found " .. tileList:GetCount() .. " tiles after scanning the " .. layerList:GetCount() .. " layers.");
//ok, now we have our list and need to run through and look at each one
while true do
tile = tileList:GetNext();
if (tile == nil) then break; end;
LogMsg("Found tile type " .. tile:GetType());
if (tile:GetType() == C_TILE_TYPE_ENTITY and tile:GetAsEntity():GetID() != this:GetID()) then
LogMsg("We are standing near an entity that isn't us! Its ID is " .. tile:GetAsEntity():GetID());
|rect||A Rect object containing the area we should grab tiles from. Any tile/entity that overlays this area will be included.|
|layers||A LayerList object containing which layers should be included for the search.|
|bWidthCollisionOnly||If true, entities/tiles without collision information will be ignored.|
Used with Map::GetCollisionByRay.
class_< vector<unsigned int> >( "LayerList" ) .def(constructor<>()) .def("Add", &vector<unsigned int>::push_back) .def("GetCount", &vector<unsigned int>::size) .def("Get", &NumberGet) .def("__tostring", &LayerListToString) ]