• <option id="kikm0"><source id="kikm0"></source></option>
  • 金沙娱东城官网


    Functions related with querying entities.


    Back to top


    public Object Crafty.map.boundaries()

    An object with the following structure, which represents an MBR which contains all entities

    Return a copy of the minimum bounding rectangle encompassing all entities.

      min: {
        x: val_x,
        y: val_y
      max: {
        x: val_x,
        y: val_y
    Back to top


    public Object Crafty.map.insert(Object obj[, Object entry])

    An entity to be inserted.


    An existing entry object to reuse. (Optional)


    An object representing this object's entry in the HashMap

    obj is inserted in '.map' of the corresponding broad phase cells. An object of the following fields is returned.

      keys: the object that keep track of cells
      obj: The inserted object
      map: the HashMap object
    Back to top


    public void Crafty.map.refresh(Entry entry)

    An entry to update

    Update an entry's keys, and its position in the broad phrase map.


    Back to top


    public void Crafty.map.remove(Entry entry)

    An entry to remove from the hashmap

    Remove an entry from the broad phase map.


    Back to top


    public void Crafty.map.traverseRay(Object origin, Object direction, Function callback)

    the point of origin from which the ray will be cast. The object must contain the properties _x and _y.


    the direction the ray will be cast. It must be normalized. The object must contain the properties x and y.


    a callback that will be called for each object that is encountered along the ray. This function is called with two arguments: The first one represents the object encountered; the second one represents the distance up to which all objects have been reported so far. The callback can return a truthy value in order to stop the traversal early.

    Traverse the spatial map in the direction of the supplied ray.

    Given the origin and direction the ray is cast and the callback is called for each object encountered in map cells traversed by the ray.

    The callback is called for each object that may be intersected by the ray. Whether an actual intersection occurs shall be determined by the callback's implementation.


          .setName('First entity')
          .attr({x: 0, y: 0, w: 10, h: 10});
          .setName('Second entity')
          .attr({x: 20, y: 20, w: 10, h: 10});
    var origin = {_x: -25, _y: -25};
    var direction = new Crafty.math.Vector2D(1, 1).normalize();
    Crafty.map.traverseRay(origin, direction, function(ent, processedDistance) {
      Crafty.log('Encountered entity named', ent.getName()); // logs 'First entity'
      Crafty.log('All entities up to', processedDistance, 'px away have been reported thus far.');
      Crafty.log('Stopping traversal after encountering the first entity.');
      return true;
    Back to top


    public Array Crafty.map.search(Object rect[, Array results])

    the rectangular region to search for entities. This object must contain the properties _x,_y,_w,_h.


    If passed, entities found will be appended to this array.


    a (possibly empty) array of entities that have been found in the given region

    Do a search for entities in the given region. Returned entities are not guaranteed to overlap with the given region, and the results may contain duplicates.

    This method is intended to be used as the first step of a more complex search. More common use cases should use Crafty.map.search, which filters the results.

    See Also