new Query(opts)
Used to perform matching of entities.
Example
//matches entities with 'Position' and 'Velocity' components
const q1 = Query({
criterions: ["Position", "Velocity"],
});
//matches entities with 'Position' and 'Velocity' components and without 'Sprite' component
const q2 = Query({
criterions: {
include: ["Position", "Velocity"],
exclude: ["Sprite"],
},
});
//matches entities of type 'Ball'
const q3 = Query({
criterions: {
entityType: "Ball",
},
});
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
opts |
Object |
Properties
|
Methods
addToIndex(entityId)
Adds entity ID to query index.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
Number |
getEntities() → {Object}
Returns entities matched by query.
Returns object with following properties:
length
- number of matched entitiesentities
- array with matched entities. This array length is usually not the same as matched entities number!
Returns:
- Type
- Object
initialize(allEntities)
Initializes query. Builds initial entities index.
Parameters:
Name | Type | Description |
---|---|---|
allEntities |
FastArray | fast array of all entities present in the engine |
removeFromIndex(entityId)
Removes entity ID from query index.
Parameters:
Name | Type | Description |
---|---|---|
entityId |
Number |
satisfiedBy(entity)
Checks if entity satisfies query criterions.
Parameters:
Name | Type | Description |
---|---|---|
entity |
Entity | entity to check |
shouldUpdate()
Checks if query should update.
Query should update when entities matching its criterions are added or removed from engine. It should also update when entity that was matching criterions has changed and doesn't match it anymore.
update(allEntities)
Updates internal matched entities with index.
Parameters:
Name | Type | Description |
---|---|---|
allEntities |
FastArray | fast array of all entities present in the engine |