BTW, the code below is what I sent in my bug report if anyone wants to take a look. Maybe I’m missing something basic.
The image is at http://mikesellsoftware.com/BeerMug.png, two source files below.
main.lua:
local physics = require("physics")
physics.start()
local group = display.newGroup()
local physicsData = (require "shapedefs").physicsData(1.0)
-- Create mug1
local mug1 = display.newImage("BeerMug.png")
mug1.x = display.contentWidth/2
mug1.y = 0
mug1.type = "mug1"
group:insert(mug1)
physics.addBody(mug1, "dynamic", physicsData:get("BeerMug"))
-- Create mug2
local mug2 = display.newImage("BeerMug.png")
mug2.x = display.contentWidth/2
mug2.y = display.contentHeight - mug2.contentHeight
mug2.type = "mug2"
group:insert(mug2)
physics.addBody(mug2, "static", physicsData:get("BeerMug"))
local function onCollision(event)
if (event.phase == "ended") then
print(event.object1.type .. ": " .. event.element1)
print(event.object2.type .. ": " .. event.element2)
end
end
Runtime:addEventListener("collision", onCollision)
shapedefs.lua:
-- This file is for use with Corona(R) SDK
--
-- This file is automatically generated with PhysicsEdtior (http://physicseditor.de). Do not edit
--
-- Usage example:
-- local scaleFactor = 1.0
-- local physicsData = (require "shapedefs").physicsData(scaleFactor)
-- local shape = display.newImage("objectname.png")
-- physics.addBody( shape, physicsData:get("objectname") )
--
-- copy needed functions to local scope
local unpack = unpack
local pairs = pairs
local ipairs = ipairs
module(...)
function physicsData(scale)
local physics = { data =
{
["IceCube"] = {
{
density = 0.5, friction = 0.2, bounce = 0.5,
filter = { categoryBits = 2, maskBits = 3 },
shape = { -10.5, 8 , -10.5, -10 , -5, 8.5 , -6, 9.5 , -9, 9.5 }
} ,
{
density = 0.5, friction = 0.2, bounce = 0.5,
filter = { categoryBits = 2, maskBits = 3 },
shape = { 9, -10.5 , 9.5, -10 , -2, 8.5 , -5, 8.5 , -10.5, -10 , -10, -10.5 }
} ,
{
density = 0.5, friction = 0.2, bounce = 0.5,
filter = { categoryBits = 2, maskBits = 3 },
shape = { -1, 9.5 , -2, 8.5 , 9.5, -10 , 9.5, 8 , 8, 9.5 }
}
}
,
["BeerMug"] = {
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 2 },
shape = { -38, 49 , -40, 2 , -33, -49 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -32, 27 , -35, 47 , -34, 9 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 15, 46 , 13, 32 , 15, 11 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -37, 52 , -13, 46 , 15, 52 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 17, 4 , 19, 48 , 10, -48 }
} ,
{
density = 2, friction = 0.4, bounce = 0.5,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 49, 31 , 13, -39 , 38, -38 }
} ,
{
density = 2, friction = 0, bounce = 0,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 21, 36 , 31, 29 , 49, 32 }
}
}
} }
-- apply scale factor
local s = scale or 1.0
for bi,body in pairs(physics.data) do
for fi,fixture in ipairs(body) do
for ci,coordinate in ipairs(fixture.shape) do
fixture.shape[ci] = s \* coordinate
end
end
end
function physics:get(name)
return unpack(self.data[name])
end
return physics;
end
[import]uid: 58455 topic_id: 12179 reply_id: 44476[/import]