I Understand

I made it such difficulter than it works

But the collisioncallbacks i dotn understand.
In the tutorial a circle falls down onto a static object.
the 4 functions for callbacks
Code: Select all
(function add(a, b, coll)
end
function persist(a, b, coll)
end
function rem(a, b, coll)
end
function result(a, b, coll)
end)
in the expample it looks like this:
Code: Select all
text = ""
function add(a, b, coll)
text = text..a.." collding with "..b.." at an angle of "..coll:getNormal().."\n"
end
function persist(a, b, coll)
text = text..a.." touching "..b.."\n"
end
function rem(a, b, coll)
text = text..a.." uncolliding "..b.."\n"
end
function result(a, b, coll)
text = text..a.." hit "..b.."resulting with "..coll:getNormal().."\n"
end
But From where come the parameter a,b and coll? i cant see them anywhere in the whole script, so it confuses me.
That u dont have to check the site again, i write the full code from the tutorial here:
Code: Select all
function love.load()
world = love.physics.newWorld(-800,-600, 800,600)
world:setGravity(0,20)
world:setCallbacks(add, persist, rem, result)
ball = {}
ball.b = love.physics.newBody(world, 400,200, 10,0)
ball.s = love.physics.newCircleShape(ball.b, 0,0, 50)
ball.s:setData("Ball")
static = {}
static.b = love.physics.newBody(world, 400,400, 0,0)
static.s = love.physics.newRectangleShape(static.b, -100,-25, 200,50, 0)
static.s:setData("Block")
end
function love.update(dt)
world:update(dt)
end
function love.draw()
love.graphics.circle("line", ball.b:getX(),ball.b:getY(), ball.s:getRadius())
local x1,y1, _,_, x3,y3, _,_ = static.s:getBoundingBox()
local w = x3-x1
local h = y3-y1
love.graphics.rectangle("line",
static.b:getX()-w/2,static.b:getY(),
w,h, 0)
love.graphics.print(text,0,12)
end
--Refer to http://love2d.org/wiki/Contact for more information on collision objects
--'coll' is an object created by the collision
--'a' is the first object in the collision and 'b' is the second
text = ""
function add(a, b, coll)
text = text..a.." collding with "..b.." at an angle of "..coll:getNormal().."\n"
end
function persist(a, b, coll)
text = text..a.." touching "..b.."\n"
end
function rem(a, b, coll)
text = text..a.." uncolliding "..b.."\n"
end
function result(a, b, coll)
text = text..a.." hit "..b.."resulting with "..coll:getNormal().."\n"
end