/// <summary> /// Gets a list of entities inside a box. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="rect">A rectangle in world coordinates.</param> /// <param name="layer">If specified, only entities in the specified vis layer will be returned.</param> /// <param name="entityList">A list that will contain the results.</param> public void GetEntitiesInBox <TEntity>(Rect rect, int?layer, List <TEntity> entityList) where TEntity : GameEntity { var possibles = _entListPool.GetObject(); _quadTree.PossibleEntitiesInBox(rect, possibles); for (var i = 0; i < possibles.Count; i++) { var possible = possibles[i]; if ((layer != null) && (possible.VisLayer != layer)) { continue; } if (possible is TEntity) { if (TestAABB(possible.WorldRect, rect)) { entityList.Add((TEntity)possible); } } } possibles.Clear(); _entListPool.PutObject(possibles); }