Flicking a ball (physic body not working)

Hello,

I am using this code for a flick, this code enables me to flick a ball. The only problem is when i download a physic body from physic editor this ball does not correspond with the physic body.

local screenW, screenH = display.stageWidth, display.stageHeight
local friction = 0.8
local gravity = .9
local speedX, speedY = 0, 0
local prevX, prevY = 0, 0

local ball = display.newCircle( 0, 0, 25)
ball:setFillColor(255, 255, 0)
ball.x = screenW*.5
ball.y = 20

function onMoveCircle(event)
speedY = speedY + gravity

ball.x = ball.x + speedX
ball.y = ball.y + speedY

if( ball.x >= screenW - ball.width*.5 ) then
ball.x = screenW - ball.width*.5
speedX = speedX*friction
speedX = speedX*-1 --change direction
elseif( ball.x <= ball.width*.5) then
ball.x = ball.width*.5
speedX = speedX*friction
speedX = speedX*-1 --change direction
end
if( ball.y >= screenH - ball.height*.5 ) then
ball.y = screenH - ball.height*.5
speedY = speedY*friction
speedX = speedX*friction
speedY = speedY*-1 --change direction
elseif( ball.y <= ball.height*.5 ) then
ball.y = ball.height*.5
speedY = speedY*friction
speedY = speedY*-1 --change direction
end
end

– A general function for dragging objects
local function startDrag( event )
local t = event.target

local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true

– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y

– Stop current motion, if any
Runtime:removeEventListener(“enterFrame”, onMoveCircle)
– Start tracking velocity
Runtime:addEventListener(“enterFrame”, trackVelocity)

elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false

Runtime:removeEventListener(“enterFrame”, trackVelocity)
Runtime:addEventListener(“enterFrame”, onMoveCircle)

end
end

– Stop further propagation of touch event!
return true
end

function trackVelocity()
speedX = ball.x - prevX
speedY = ball.y - prevY

prevX = ball.x
prevY = ball.y
end

ball:addEventListener(“touch”, startDrag)
Runtime:addEventListener(“enterFrame”, onMoveCircle)

local scaleFactor = 1.0
local physicsData = (require “hoop2”).physicsData(scaleFactor)
local hoop2 = display.newImage (“hoop2.png”)
hoop2.x = display.contentHeight/2
hoop2.y = display.contentWidth/0.8
hoop2.rotation = -90
physics.addBody( hoop2, “static”,physicsData:get(“hoop2”) )
The code for the physic body, from physic editor. Do you know why once i had the flick option the physic body does not correspond ? Thank you.

– This file is for use with Corona Game Edition

– 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 =
{

[“hoop2”] = {

{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -80, 31.5 , -80, -80.5 , -79, -80.5 , -71.5, -79 , -71.5, 31 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -71.5, 17 , -71.5, -9 , -65, -8.5 , -62, 0.5 , -62, 8.5 , -63.5, 15 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 18.5, 35 , 11, 36 , 37, 4.5 , 42.5, 5 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 18.5, 35 , 15, 76.5 , 9, 73 , 11, 36 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { 0, 77.5 , -29, 74 , 9, 73 , 15, 76.5 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -27, 80.5 , -35, 80.5 , -34, 79.5 , -18, 78.5 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -10, 79.5 , -34, 79.5 , -37, 78.5 , -29, 74 , 0, 77.5 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -37, 78.5 , -34, 79.5 , -35, 80.5 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -37, 78.5 , -42.5, 34 , -34, 37 , -29, 74 }
} ,
{
density = 2, friction = 0.02, bounce = 0.01,
filter = { categoryBits = 1, maskBits = 65535 },
shape = { -49.5, 27 , -62, 8.5 , -62, 0.5 , -34, 37 , -42.5, 34 }
}
}

} }

– 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: 66985 topic_id: 10956 reply_id: 310956[/import]