Skip to content

Commit

Permalink
Add onCollision method.
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed May 23, 2017
1 parent f6ecc00 commit ec4f92c
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Coffeescript linter (http://www.coffeelint.org/)
- Unobserve elements on removal
- Add onCollision method

## [1.0.6](https://github.com/elbywan/quadtree-lib/compare/1.0.5...1.0.6)

Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ var colliding = quadtree.colliding({

```

### Perform an action on colliding elements

Performs an action on every element that collides with the parameter 2d object.

```javascript
onCollision({
x: 10,
y: 20
}, function(item) {
/* Action on colliding item */

// As with all iterative methods, modifying the quadtree or its contents is discouraged. //
}, function(element1, element2){
/* Optional custom collision algorithm */
return // Place predicate here //
})
```

### Retrieve by properties

Gets every element that match the parameter properties.
Expand Down Expand Up @@ -217,6 +235,8 @@ Performs an action on each element of the Quadtree (breadth first traversal).
```javascript
quadtree.each(function(element){
console.log(element.color)

// As with all iterative methods, modifying the quadtree or its contents is discouraged. //
})
```

Expand All @@ -231,6 +251,8 @@ quadtree.visit(function(){
// This function is called once for each node.
// *this* is a pointer to the current node.
console.log(this.contents)

// As with all iterative methods, modifying the quadtree or its contents is discouraged. //
})
```

Expand Down
52 changes: 51 additions & 1 deletion build/js/quadtree.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/js/quadtree.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/js/quadtree.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/js/quadtree.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit ec4f92c

Please sign in to comment.