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:
-
game
Game- Game instance this
MultiObjectManager
is attached to.
- Game instance this
-
ObjectConstructor
Object- 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:
-
x
Number- Map tile coord x.
-
y
Number- Map tile coord y.
-
obj
Object | String- The Object being set at given coords. If
obj
is 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:
-
x
Number- The tile map x coord.
-
y
Number- 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:
-
x
Number- Map tile x coord.
-
y
Number- Map tile y coord;
-
[settings]
Object optional
Returns:
getFirst
-
x
-
y
-
[filter]
Retrieves the first object in array at given map tile coord.
Parameters:
-
x
Number- The tile map x coord.
-
y
Number- 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:
-
x
Number- The tile map x coord.
-
y
Number- 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:
-
mapData
Array- The array of strings to load.
-
charToType
Object- 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
mapData
not found incharToType
will 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:
-
type
String- The type to make the object
Returns:
move
-
x
-
y
-
object
Changes the position of an entity already added to this entityManager.
Parameters:
-
x
Number- The new map tile coordinate position of the entity on the x axis.
-
y
Number- The new map tile coordinate position of the entity on the y axis.
-
object
Obj- The objectity to be removed.
remove
-
obj
Removes an entity from the manager.
Parameters:
-
obj
Obj- The objity to be removed.
removeAt
-
x
-
y
-
[filter]
Remove all objects from given location.
Parameters:
-
x
Number- Tile map x coord.
-
y
Number- 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:
-
width
Number- Width of current map in tiles.
-
height
Number- 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