At least those two points can be handled more gracefully:Tesselode wrote:3. Use an if statement: if (shape1 = your first shape and shape2 = your second shape) OR if (shape1 = your second shape and shape2 = your first shape)
4. Figure out which bodies the shapes apply to so you can make them react properly.
You can attach data to a shape using Shape:setData. This data can be any Lua value; especially it can be a table. Attach a table with the body and some id field:
Code: Select all
theShape:setData {
body = theBody,
id = theID, -- this again can be any lua value
}
Code: Select all
dispatcher = {}
dispatcher[id1] = {}
dispatcher[id1][id2] = function(a, b) --[[ do stuff --]] end
dispatcher[id1][id3] = function(a, b) --[[ do stuff --]] end
dispatcher[id2] = {}
dispatcher[id2][id4] = function(a, b, contact) --[[ do stuff --]] end
Code: Select all
function persist(a,b,contact)
if dispatcher[a.id] and dispatcher[a.id][b.id] then
dispatcher[a.id][b.id](a,b,contact)
elseif dispatcher[b.id] and dispatcher[b.id][a.id] then
dispatcher[b.id][a.id](b,a,contact)
end
end