You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2019. It is now read-only.
Jasper edited this page Apr 22, 2014
·
2 revisions
Problem: Repeated searching through arrays to find specific objects.
Solution: Physics.query
Queries are test functions that can be run on an object to see if it matches a specific format. Query functions are created with the Physics.query helper which follows mongodb-like syntax.
Example:
varwheelsArray=[];varqueryFn=Physics.query({name: 'circle',// only circles$nin: wheelsArray,// not in the wheelsArraylabels: {$in: ['player','monster']}// that have player OR monster labels});varobj={name: 'circle',labels: ['round']};queryFn(obj);// -> false// give it a player tagobj.labels.push('player');queryFn(obj);// -> true// put it inside the wheelsArraywheelsArray.push(obj);queryFn(obj);// -> false