diff --git a/index.html b/index.html index af5a141..d4094e3 100644 --- a/index.html +++ b/index.html @@ -75,15 +75,9 @@ -- array to hold collision messages local text = {} --- this is called when two shapes begin colliding -function collision_start(dt, shape_a, shape_b, mtv_x, mtv_y) - text[#text+1] = string.format("Started colliding. mtv = (%s,%s)", - mtv_x, mtv_y) -end - --- this is called when two shapes continue colliding -function collision_persist(dt, shape_a, shape_b, mtv_x, mtv_y) - text[#text+1] = string.format("Still colliding. mtv = (%s,%s)", +-- this is called when two shapes collide +function on_collision(dt, shape_a, shape_b, mtv_x, mtv_y) + text[#text+1] = string.format("Colliding. mtv = (%s,%s)", mtv_x, mtv_y) end @@ -94,7 +88,7 @@ end function love.load() -- initialize library - HC.init(100, collision_start, collision_persist, collision_stop) + HC.init(100, on_collision, collision_stop) -- add a rectangle to the scene rect = HC.addRectangle(200,400,400,20) diff --git a/reference.html b/reference.html index 1e8812c..9e5c918 100644 --- a/reference.html +++ b/reference.html @@ -83,6 +83,10 @@
Group shapes that should not collide.
removeFromGroup()
Remove shape from a group.
+
setPassive()
+
Stops shape actively searching for collision candidates.
+
setActive()
+
Let shape actively search for collision candidates.
setGhost()
Stops shape from colliding.
setSolid()
@@ -92,18 +96,16 @@
-

function init(cell_size, callback_start, callback_persist, callback_stop)^ top

+

function init(cell_size, callback_collide, callback_stop)^ top

Initializes the library. Call this in love.load(). All the parameters can be omitted.

Parameters:
number cell_size (100)
Cell size for internal search structure.
-
function callback_start (empty function)
-
Called when two shapes start colliding.
-
function callback_persist (empty function)
-
Called when two continue to collide, i.e. if the collision lasts more than one frame.
+
function callback_collide (empty function)
+
Called when two shapes collide.
function callback_stop (empty function)
-
Called when two shapes stop colliding.
+
Called when two shapes stopped colliding.
Returns: @@ -120,24 +122,22 @@ end
-

function setCallbacks(start,persist,stop)^ top

-

function setCallbacks{start = start,persist = persist,stop = stop}

+

function setCallbacks(collide, stop)^ top

+

function setCallbacks{collide = collide, stop = stop}

Sets the different callbacks. The second calling style let's you specify the callbacks by name, see the example.

If nil is passed as any callback, the callback will not be changed.

-

Each callback has the following prototype: +

The callbacks have the following function prototype:

function callback(dt, shape_one, shape_two, mtv_x, mtv_y)
- The two shape parameters are the colliding shapes. The last two parameters, mtv_x and mtv_y + shape_one and shape_two are the colliding shapes. mtv_x and mtv_y define the minimum translation vector, i.e. the direction and magnitude shape_one has to be moved so that the collision will be resolved. Note that if one of the shapes is a point shape, the translation vector will be invalid.

Parameters:
-
function start
-
Called when two shapes start colliding.
-
function persist
-
Called when two continue to collide, i.e. if the collision lasts more than one frame.
-
function stop
-
Called when two shapes stop colliding.
+
function callback_collide
+
Called when two shapes collide.
+
function callback_stop
+
Called when two shapes stopped colliding.
Returns: @@ -146,20 +146,15 @@ end
Example: -
function start(dt, shape_one, shape_two, mtv_x, mtv_y)
-    print('started colliding:', shape_one, shape_two)
-	print('mtv:', mtv_x, mtv_y)
-end
-
-function persist_one(dt, shape_one, shape_two, mtv_x, mtv_y)
-    print('still colliding:', shape_one, shape_two)
+			
function collide_one(dt, shape_one, shape_two, mtv_x, mtv_y)
+    print('colliding:', shape_one, shape_two)
     -- move both shape_one and shape_two to resolve the collision
     shape_one:move(mtv_x/2, mtv_y/2)
     shape_two:move(-mtv_x/2, -mtv_y/2)
 end
 
-function persist_two(dt, shape_one, shape_two, mtv_x, mtv_y)
-    print('still colliding:', shape_one, shape_two)
+function collide_two(dt, shape_one, shape_two, mtv_x, mtv_y)
+    print('colliding:', shape_one, shape_two)
     -- move only shape_one to resolve the collision
     shape_one:move(mtv_x, mtv_y)
 end
@@ -172,9 +167,9 @@ end
 function love.load()
     hardoncollider.init(100)
     -- set initial callbacks
-    hardoncollider.setCallbacks(start, persist_one, stop)
+    hardoncollider.setCallbacks(collide_one, stop)
     -- change persist callback
-    hardoncollider.setCallbacks{persist = persist_two}
+    hardoncollider.setCallbacks{collide = collide_two}
 end
@@ -183,8 +178,6 @@ end

function update(dt)^ top

Checks for collisions and call callbacks. Use this in love.update(dt).

-

A maximum time delta can be specified. dt will be chopped up in slices - not bigger than this maximum and the scene is updated for each time slice.

Note that the delta time has no effect on the collision detection itself, but will be passed to the callback functions.

@@ -453,6 +446,53 @@ end
+ +
+

function setPassive(shape, ...)^ top

+

Sets shape to be passive. Passive shapes will be subject to collision detection, + but will not actively search for collision candidates. This means that if two + passive shapes collide, no collision callback will be invoked (in fact, the + collision won't even be detected).

+

This function exists purely for performance optimisation. Use it wisely. + Good candidates for passive shapes are traps and terrain.

+

Note: Shapes are active by default

+
Parameters: +
+
Shapes shape, ...
+
The shapes to become passive.
+
+
+
Returns: +
+
Nothing
+
+
+
Example: +
hardoncollider.setPassive(ground, bridge, spikes)
+
+
+ + +
+

function setActive(shape, ...)^ top

+

Makes shapes active again.

+

Note: Shapes are active by default

+
Parameters: +
+
Shapes shape, ...
+
The shapes to become active.
+
+
+
Returns: +
+
Nothing
+
+
+
Example: +
hardoncollider.setActive(collapsing_bridge)
+
+
+

function setGhost(shape, ...)^ top

diff --git a/tutorial.html b/tutorial.html index 07e4d88..6855ef8 100644 --- a/tutorial.html +++ b/tutorial.html @@ -108,7 +108,7 @@ end in which we will handle what should happen when two shapes collide. We will cover the different parameters later.

HC.init(100, on_collide) - initializes the library, setting the on_collide + initializes the library, setting on_collide as callback function. The first argument defines a cell size which is used internally to speed things up. You don't have to worry about that at the moment.