Packagecom.pblabs.rendering2D
Classpublic class BasicSpatialManager2D
InheritanceBasicSpatialManager2D Inheritance EntityComponent Inheritance Object
Implements ISpatialManager2D

Basic 2d spatial manager that stores everything in a list. There are many smarter implementations, but this one is simple and reliable.



Public Properties
 PropertyDefined By
 InheritedisRegistered : Boolean
[read-only] Whether or not the component is currently registered with an entity.
EntityComponent
 Inheritedname : String
[read-only] The name given to the component when it is added to an entity.
EntityComponent
 Inheritedowner : IEntity
A reference to the entity that this component currently belongs to.
EntityComponent
Protected Properties
 PropertyDefined By
  _objectList : Array
BasicSpatialManager2D
Public Methods
 MethodDefined By
  
Add a generic spatial object to this manager.
BasicSpatialManager2D
  
boxVsBox(box1:Rectangle, box2:Rectangle):Boolean
Determines if the two rectangles intersect.
BasicSpatialManager2D
  
castRay(start:Point, end:Point, mask:ObjectType, result:RayHitInfo):Boolean
Cast a ray and (optionally) return information about what it hits in result.
BasicSpatialManager2D
  
getObjectsUnderPoint(worldPosition:Point, results:Array, mask:ObjectType = null):Boolean
Return all the spatial objects under a given point.
BasicSpatialManager2D
  
queryCircle(center:Point, radius:Number, mask:ObjectType, results:Array):Boolean
Return all the spatial objects that overlap the specified circle.
BasicSpatialManager2D
  
queryRectangle(box:Rectangle, mask:ObjectType, results:Array):Boolean
Return all the spatial objects that overlap with the specified box and match one or more of the types in the mask.
BasicSpatialManager2D
 Inherited
register(owner:IEntity, name:String):void
Registers the component with an entity.
EntityComponent
  
Remove a previously registered object from this manager.
BasicSpatialManager2D
 Inherited
reset():void
This is called by an entity on all of its components any time a component is added or removed.
EntityComponent
 Inherited
unregister():void
Unregisters the component from an entity.
EntityComponent
Protected Methods
 MethodDefined By
 Inherited
onAdd():void
This is called when the component is added to an entity.
EntityComponent
 Inherited
onRemove():void
This is called when the component is removed from an entity.
EntityComponent
 Inherited
onReset():void
This is called anytime a component is added or removed from the owner entity.
EntityComponent
Public Constants
 ConstantDefined By
  EntitiesDirtyEvent : String = BasicSpatialManager2D.EntitiesDirty
[static] An event with this name is raised on the owner.eventDispatcher when the entity list changes via addSpatialObject or removeSpatialObject.
BasicSpatialManager2D
Property Detail
_objectListproperty
protected var _objectList:Array

Method Detail
addSpatialObject()method
public function addSpatialObject(object:ISpatialObject2D):void

Add a generic spatial object to this manager. A manager with advanced functionality will support both general ISpatialObject2D implementations as well as enabling special functionality for its peered classes.

Parameters

object:ISpatialObject2D

boxVsBox()method 
public function boxVsBox(box1:Rectangle, box2:Rectangle):Boolean

Determines if the two rectangles intersect. This, along with the objectMask of the spatial component is used in queryRectangle to determine which spatial components are added to the results array.

Parameters

box1:Rectangle
 
box2:Rectangle

Returns
Boolean
castRay()method 
public function castRay(start:Point, end:Point, mask:ObjectType, result:RayHitInfo):Boolean

Cast a ray and (optionally) return information about what it hits in result.

Parameters

start:Point
 
end:Point
 
mask:ObjectType
 
result:RayHitInfo

Returns
Boolean
getObjectsUnderPoint()method 
public function getObjectsUnderPoint(worldPosition:Point, results:Array, mask:ObjectType = null):Boolean

Return all the spatial objects under a given point. Objects can optionally implement pixel-level collision checking.

Parameters

worldPosition:Point — Point in worldspace to check.
 
results:Array — An array into which ISpatialObject2Ds are added based on what is under point.
 
mask:ObjectType (default = null) — Only consider objects that match this ObjectType. Null uses all types.

Returns
Boolean — Found something under point or not.
queryCircle()method 
public function queryCircle(center:Point, radius:Number, mask:ObjectType, results:Array):Boolean

Return all the spatial objects that overlap the specified circle.

Parameters

center:Point
 
radius:Number
 
mask:ObjectType
 
results:Array

Returns
Boolean
queryRectangle()method 
public function queryRectangle(box:Rectangle, mask:ObjectType, results:Array):Boolean

Return all the spatial objects that overlap with the specified box and match one or more of the types in the mask.

Note that if you pass in a populated array, this method appends to it. This can be useful if you want to combine the results of several queries. If you just want the results from one query, make sure to set results.length=0; before you pass it to queryRectangle.

Parameters

box:Rectangle
 
mask:ObjectType
 
results:Array

Returns
Boolean — True if one or more objects were found and push()'ed to results.
removeSpatialObject()method 
public function removeSpatialObject(object:ISpatialObject2D):void

Remove a previously registered object from this manager.

Parameters

object:ISpatialObject2D

Constant Detail
EntitiesDirtyEventConstant
public static const EntitiesDirtyEvent:String = BasicSpatialManager2D.EntitiesDirty

An event with this name is raised on the owner.eventDispatcher when the entity list changes via addSpatialObject or removeSpatialObject.