I can give you a condensed version of the project - it’s a good deal of ugly code, but it’s probably needed to replicate the problem, if you have the patience.
It occurs sometimes when the bat is moving, and it’s supposed to hit a ball travelling at high speed
Cheers!
main.lua
[lua]
system.activate( “multitouch” )
local physics = require “physics”
physics.setDrawMode( “hybrid” )
physics.start()
physics.setTimeStep( 0 )
physics.setContinuous(enabled)
physics.setGravity( 0, 44)
physics.setPositionIterations( 48 )
physics.setVelocityIterations( 64 )
local flipSpeed = 1000
local frameGroup = display.newGroup()
frameGroup.anchorX = 0.5
– walls and stuff
physics.addBody(display.newRect(frameGroup,-5,-1000,2200,20),“static”,{ density = 1.0, friction = 0.5, bounce = 0.7})
physics.addBody(display.newRect(frameGroup,-5,-5,20,2000),“static”,{ density = 1.0, friction = 0.5, bounce = 0.7})
physics.addBody(display.newRect(frameGroup,1024,-5,20,2024),“static”,{ density = 1.0, friction = 0.5, bounce = 0.7})
physics.addBody(display.newRect(frameGroup,-5,1000,2209,20),“static”,{ density = 1.0, friction = 0.5, bounce = 0.7})
local leftSlide = display.newRect(frameGroup,207,487,270,20)
leftSlide.rotation =20
physics.addBody(leftSlide,“static”,wallMaterial)
local ldown = display.newRect(frameGroup,80,325,10,250)
physics.addBody(ldown,“static”,wallMaterial)
local rleftSlide = display.newRect(frameGroup,808,490,270,20)
rleftSlide.rotation =-20
physics.addBody(rleftSlide,“static”,wallMaterial)
local rldown = display.newRect(frameGroup,945,325,10,250)
physics.addBody(rldown,“static”,wallMaterial)
local topSlide = display.newRect(frameGroup,800,-480,500,-10)
topSlide.rotation =20
topSlide.x = 500
physics.addBody(topSlide,“static”,{ density = 1.0, friction = 0.5, bounce = 0.7})
topSlide.level = 2
local topSlide2 = display.newRect(frameGroup,800,-650,400,-10)
topSlide2.rotation =-20
topSlide2.x = 700
physics.addBody(topSlide2,“static”,{ density = 1.0, friction = 0.5, bounce = 0.7})
— flippers
local lx = 330
local ly = 532
local lfShape = {
-65,-20,
60,-10,
60,10,
-65,20
}
local leftFlipper = display.newPolygon( frameGroup, lx, ly, lfShape )
leftFlipper.x = lx+83
leftFlipper.y = ly+15
local leftPivot = display.newCircle(frameGroup, lx+15, ly+15, 20 )
physics.addBody( leftFlipper, “dynamic”, { density=10.0, friction=0.8, bounce=0.2, shape=lfShape } )
physics.addBody( leftPivot, “static”, { density=2, radius=5, friction=2.5, bounce=0.5} )
leftFlipper.isBullet = true
local leftJoint = physics.newJoint( “pivot”, leftPivot, leftFlipper, leftPivot.x, leftPivot.y )
leftJoint.isLimitEnabled = true
leftJoint:setRotationLimits( -20, 15)
leftJoint.isMotorEnabled = true
leftJoint.maxMotorTorque = 100000
leftJoint.motorTorque = 70000
leftFlipper.isBullet = true
local rx = 690
local ry = 532
local rfShape = { 60,-20, -60,-10, -60,10, 60,20}
local rightFlipper = display.newPolygon( frameGroup, rx, ry, rfShape )
rightFlipper.x = rx-82
rightFlipper.y = ry+15
local rightPivot = display.newCircle(frameGroup, rx-15, ry+15, 20 )
physics.addBody( rightFlipper, “dynamic”, { density=10.0, friction=0.8, bounce=0.1, shape=rfShape } )
physics.addBody( rightPivot, “static”, { density=2, radius=5, friction=2.5, bounce=0.5} )
local rightJoint = physics.newJoint( “pivot”, rightPivot, rightFlipper, rightPivot.x, leftPivot.y )
rightJoint.isLimitEnabled = true
rightJoint:setRotationLimits( -15, 20)
rightJoint.isMotorEnabled = true
rightJoint.maxMotorTorque = 100000
rightJoint.motorTorque = 70000
rightFlipper.isBullet = true
local ball = display.newCircle(frameGroup, 0, 0, 20);
ball.x, ball.y = 90, 222;
physics.addBody(ball, “dynamic”, {friction = 0.5, density = 2.5, bounce = 0, radius = 20});
ball.isBullet = true;
local function flipLeft()
if(leftFlipper.active == false) then
leftFlipper.active = true
end
end
local function flipRight()
if(rightFlipper.active == false) then
rightFlipper.active = true
end
end
local function dropLeft()
leftFlipper.active = false
leftJoint.motorSpeed = flipSpeed
end
local function dropRight()
rightFlipper.active = false
rightJoint.motorSpeed = -flipSpeed
end
function leftFlipper:enterFrame()
if self.active then
leftJoint.motorSpeed = -flipSpeed
end
end
Runtime:addEventListener(“enterFrame”, leftFlipper);
function ball:enterFrame()
if (ball.y > 900) then
ball.x = 130
ball.y = 0
end
frameGroup.y = -ball.y + 400
end
Runtime:addEventListener(“enterFrame”, ball);
function rightFlipper:enterFrame()
if self.active then
rightJoint.motorSpeed = flipSpeed
end
end
Runtime:addEventListener(“enterFrame”, rightFlipper);
local function listener(event)
if(event.phase == “began” or event.phase == “moved”) then
if(event.x > 600) then
flipRight()
else
flipLeft()
end
elseif(event.phase == “ended” or event.phase == “cancelled”) then
if(event.x > 600) then
dropRight()
else
dropLeft()
end
end
return true
end
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
local returnValue = false
print(phase)
if(phase == “down”) then
if(keyName == “right”) then
flipRight(event)
end
if(keyName == “left”) then
flipLeft(event)
end
elseif(event.phase == “up”) then
if(keyName == “right”) then
dropRight()
end
if(keyName == “left”) then
dropLeft()
end
end
end
– Add the key callback
Runtime:addEventListener( “key”, onKeyEvent )
Runtime:addEventListener( “touch”, listener )
[/lua]
build.settings:
[lua]
settings =
{
orientation =
{
default = “landscapeRight”,
supported =
{
“landscapeRight”
}
}
}
[/lua]
config.lua
[lua]
application =
{
launchPad = false,
content =
{
fps = 60,
width = 600,
height = 1024,
scale = “letterbox”,
antialias = true,
},
}
[/lua]