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 @@
Initializes the library. Call this in love.load()
. All the parameters can be omitted.
cell_size
(100)callback_start
(empty function)callback_persist
(empty function)callback_collide
(empty function)callback_stop
(empty function)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.
start
persist
stop
callback_collide
callback_stop
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
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 @@ endSets 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
+shape, ...
hardoncollider.setPassive(ground, bridge, spikes)
+ Makes shapes active again.
+Note: Shapes are active by default
+shape, ...
hardoncollider.setActive(collapsing_bridge)
+ 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.