Methods
-
<static> addType(classObject, entity, property, names, typeListName)
-
Adds space separated type flags by name to a property of an entity. In ImpactJS, there are 3 default types: A, B, and BOTH. This system allows you to build up to 32 types for much finer control over type, checkAgainst, and group. If you don't understand bitflags, a quick google search will be very helpful!
Parameters:
- currently, Impact++ uses around 10 types/flags (see example)
- to avoid poor performance, only use this when initializing an entity IMPORTANT: maxes out at 32 types/flags due to the way Javascript handles bitwise operations.Name Type Argument Description classObjectClass class object to record types in. entityig.EntityExtended entity to add types to. propertyString property name within entity to add types to. namesString space separated names to create type for. typeListNameString <optional>
list name to store types in, defaults to TYPE. - Source:
// spawn an entity var entity = ig.game.spawnEntity( ig.EntityExtended, 0, 0, { ...settings...} ); // add a type to our new entity // this type system defaults to using TYPE as the namespace to record unique types ig.utils.addType( ig.EntityExtended, entity, "type", "TYPE_NAME" ); // when we need to do dynamic checks for that type // refer to it directly using the TYPE namespace ig.EntityExtended.TYPE.TYPE_NAME // and a check against the type of our new entity will return truthy entity.type & ig.EntityExtended.TYPE.TYPE_NAME // we can also add a GROUP type to our new entity // note the last argument, we're using the GROUP namespace // this is because group types should be different from TYPE types ig.utils.addType( ig.EntityExtended, entity, "group", "GROUP_NAME", "GROUP" ); // refer to it directly using the GROUP namespace ig.EntityExtended.GROUP.GROUP_NAME // remember, types and groups can be added together to make combinations! ig.utils.addType( ig.EntityExtended, entity, "type", "TYPE_1" ); ig.utils.addType( ig.EntityExtended, entity, "type", "TYPE_2" ); ig.utils.addType( ig.EntityExtended, entity, "type", "TYPE_3" ); // and we can still check for any one or more of those types easily entity.type & ig.EntityExtended.TYPE.TYPE_1 === truthy entity.type & ( ig.EntityExtended.TYPE.TYPE_1 | ig.EntityExtended.TYPE.TYPE_2 ) === truthy entity.type & ig.EntityExtended.TYPE.TYPE_4 === falsy -
<static> arrayCautiousAdd(target, element) → {Array}
-
Add element to target array only if not already in array. IMPORTANT: this modifies the array in place.
Parameters:Name Type Description targetArray Target array element* Single value to add - Source:
{ Array } Array containing elements -
<static> arrayCautiousAddMulti(target, elements) → {Array}
-
Add elements to target array only if not already in array. IMPORTANT: this modifies the array in place.
Parameters:Name Type Description targetArray Target array elements* Single object or array of values to add - Source:
{ Array } Array containing elements -
<static> arrayCautiousRemove(target, element) → {Array}
-
Removes element from target array. IMPORTANT: this modifies the array in place.
Parameters:Name Type Description targetArray Target array element* Single value to remove - Source:
{ Array } Array containing elements -
<static> arrayCautiousRemoveMulti(target, elements) → {Array}
-
Removes elements from target array. IMPORTANT: this modifies the array in place.
Parameters:Name Type Description targetArray Target array elements* Single object or array of values to remove - Source:
{ Array } Array containing elements -
<static> debounce(callback, delay) → {function}
-
Debounce a function to execute only once delay reached between subsequent calls, based on Ben Alman's jQuery Throttle / Debounce.
Parameters:Name Type Argument Description callbackfunction Callback function delayNumber <optional>
Delay in ms - Source:
{ function } Debounced function. -
<static> forEach(array, callback, args)
-
Executes a callback on each item in an array, in the context of that item.
Parameters:Name Type Description arrayArray Array to iterate over callbackCallback Callback to call argsArray Arguments to pass - Source:
-
<static> getType(classObject, names, typeListName)
-
Gets a type flag by space separated names, and if does not exists, creates it. In ImpactJS, there are 3 default types: A, B, and BOTH. This system allows you to build up to 32 types for much finer control over type, checkAgainst, and group. If you don't understand bitflags, a quick google search will be very helpful!
Parameters:
- currently, Impact++ uses around 10 types/flags (see example)
- to avoid poor performance, only use this when initializing an entity IMPORTANT: maxes out at 32 types/flags due to the way Javascript handles bitwise operations.Name Type Argument Description classObjectClass class / object to record types in. namesString space separated names to create type for. typeListNameString <optional>
list name to store types in, defaults to TYPE. - Source:
- See:
-
<static> indexOfProperties(array, properties, values) → {Number}
-
Find the index of an object in an array matching all property values.
Parameters:Name Type Description arrayArray Array to search. propertiesArray Property names. valuesArray Values to match. - Source:
{ Number } >= 0 if found, -1 if not -
<static> indexOfProperty(array, property, value) → {Number}
-
Find the index of an object in an array with property = value.
Parameters:Name Type Description arrayArray Array to search propertyString Property name value* Value of property to match - Source:
{ Number } >= 0 if found, -1 if not -
<static> indexOfValue(array, value) → {Number}
-
Find the index of value in an array. Tip: in some cases, this may be faster than the native indexOf.
Parameters:Name Type Description arrayArray Array to search value* Value of property to match - Source:
{ Number } >= 0 if found, -1 if not -
<static> isArray(target) → {Boolean}
-
Checks if target is array.
Parameters:Name Type Description target* target object - Source:
{ Boolean } true if array, false if not -
<static> isNumber(n) → {Boolean}
-
Checks if target is number.
Parameters:Name Type Description nNumber number - Source:
{ Boolean } true if number, false if not -
<static> throttle(callback, delay, trailing) → {function}
-
Throttle a function to execute no more than once per delay (its like a cooldown), based on Ben Alman's jQuery Throttle / Debounce.
Parameters:Name Type Argument Description callbackfunction Callback function delayNumber <optional>
Delay in ms trailingBoolean <optional>
Whether to allow a trailing execution - Source:
- See:
{ function } Throttled function. -
<static> toArray(target) → {Array}
-
Ensures an object is an array.
Parameters:Name Type Description target* target object - Source:
{ Array } Array -
<static> toNotArray(target, index) → {*}
-
Ensures an object is not an array.
Parameters:Name Type Argument Default Description target* target object indexNumber <optional>
0 index of array to use if target is an array. - Source:
{ * } item at index of array -
<static> type(o) → {String}
-
Finds javascript type of object, slower than typeof or instanceof but sometimes necessary.
Parameters:Name Type Description o* target object - Source:
{ String } Type of object

Impact++