MultiObjectManager Class
Manages a list of object and their tile positions. Multiple objects can be at a given tile map coord. Handles adding, removing, moving objects within the game.
Constructor
MultiObjectManager
-
game -
ObjectConstructor -
[width] -
[height]
Parameters:
-
gameGame- Game instance this
MultiObjectManageris attached to.
- Game instance this
-
ObjectConstructorObject- Object constructor used to create new objects with
this.add().
- Object constructor used to create new objects with
-
[width]Number optional- Width of current map in tiles.
-
[height]Number optional- Height of current map in tiles.
Item Index
Methods
Methods
add
-
x -
y -
obj
Adds an object to the manager at given map tile coord. Multiple objects can be added to the same coord.
Parameters:
-
xNumber- Map tile coord x.
-
yNumber- Map tile coord y.
-
objObject | String- The Object being set at given coords. If
objis a string a new Object will be created usingthis.makeNewObjectFromType(obj).
- The Object being set at given coords. If
Returns:
The added object.
get
-
x -
y -
[filter]
Retrieves all objects at given map tile coord.
Parameters:
-
xNumber- The tile map x coord.
-
yNumber- The tile map y coord.
-
[filter]Function optional- A function to filter the array of objects returned
function(object){ return true }.
- A function to filter the array of objects returned
Returns:
getAdjacent
-
x -
y -
[settings]
Same as this.map.getAdjacent, but merges all results into on flat array.
Parameters:
-
xNumber- Map tile x coord.
-
yNumber- Map tile y coord;
-
[settings]Object optional
Returns:
getFirst
-
x -
y -
[filter]
Retrieves the first object in array at given map tile coord.
Parameters:
-
xNumber- The tile map x coord.
-
yNumber- The tile map y coord.
-
[filter]Function optional- A function to filter the object returned at this map tile coord
function(object){ return true }. The first object in the array the filter matches is returned.
- A function to filter the object returned at this map tile coord
Returns:
getLast
-
x -
y -
[filter]
Retrieves the last object in array at given map tile coord.
Parameters:
-
xNumber- The tile map x coord.
-
yNumber- The tile map y coord.
-
[filter]Function optional- A function to filter the object returned at this map tile coord
function(object){ return true }. The last object in the array the filter matches is returned.
- A function to filter the object returned at this map tile coord
Returns:
loadEntitiesFromArrayString
-
mapData -
charToType -
[defaultType]
Loads Obj data from an array of strings.
Parameters:
-
mapDataArray- The array of strings to load.
-
charToTypeObject- An object mapping string characters to Obj types (see Obj.Types[type]). Characters in mapData not in charToType are ignored.
-
[defaultType]String optional- If set, all characters in
mapDatanot found incharToTypewill be replaced by an object withdefaultType.
- If set, all characters in
Example:
var mapData = [
'####',
'#..#',
'#.Z#',
'####',
],
charToType = {
'Z': 'zombie'
};
entityManager.loadTilesFromArrayString(mapData, charToType);
makeNewObjectFromType
-
type
Creates a new object instance.
Parameters:
-
typeString- The type to make the object
Returns:
move
-
x -
y -
object
Changes the position of an entity already added to this entityManager.
Parameters:
-
xNumber- The new map tile coordinate position of the entity on the x axis.
-
yNumber- The new map tile coordinate position of the entity on the y axis.
-
objectObj- The objectity to be removed.
remove
-
obj
Removes an entity from the manager.
Parameters:
-
objObj- The objity to be removed.
removeAt
-
x -
y -
[filter]
Remove all objects from given location.
Parameters:
-
xNumber- Tile map x coord.
-
yNumber- Tile map y coord.
-
[filter]Function optional- A function to filter the objects removed
function(object){ return true }.
- A function to filter the objects removed
reset
()
Resets this entityManager.
setSize
-
width -
height
Sets the size of the map to manage objects within.
Parameters:
-
widthNumber- Width of current map in tiles.
-
heightNumber- Height of current map in tiles.
update
-
[excludeObject]
Calls the object.update() method on all objects. Removes object.dead == true objects.
Typically called after a player has resolved their actions.
Not all object managers need to upade the objects they manage.
Parameters:
-
[excludeObject]Object optional- excludeObject will be skipped if found in
this.objects.
- excludeObject will be skipped if found in
