Basically when the user draws slowly the game runs fine however if the user starts drawing really fast the game comes to a stand still until all of the drawing lines are made. Thanks
By the way it runs perfect in the simulator but not on the phone I tested it on iPhone 4 and iPhone 5.
[lua]
– General Setup: Variables and Tables ==============
local atan2 = math.atan2
local pi= math.pi
width = display.contentWidth
height = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)
configDraw = {}
configDraw.type = “continuous”
configDraw.w = 15; configDraw.length = 50^2; configDraw.state = nil
drawTable = {}
cords = {}; cords.drawX = nil; cords.drawY = nil
–===================================================
function startDraw( draw )
if draw.phase == “began” then
configDraw.state = “inProgress”
cords.drawX = draw.x
cords.drawY = draw.y
drawTable[#drawTable+1] = display.newCircle(draw.x,draw.y, configDraw.w/2)
drawTable[#drawTable]:setFillColor(255,10,10)
drawTable[#drawTable].x = draw.x
drawTable[#drawTable].y = draw.y
end
– changes the coordinants of where the persons finger is at
if draw.phase == “moved” and
configDraw.state == “inProgress” then
cords.drawX = draw.x
cords.drawY = draw.y
end
if configDraw.type == “continuous” and
draw.phase == “moved” and
configDraw.state == “inProgress” and
overload == nil and
drawTable[1] ~= nil and
(math.abs(drawTable[#drawTable].x-cords.drawX)^2 + – Makes sure the persons finer is
math.abs(drawTable[#drawTable].y-cords.drawY)^2 – Farther away then the configDraw.length
) > configDraw.length then
createDrawLines(draw)
for a,b in pairs(drawTable) – tells me number of items in the table
do print(a, B)
end
end
if draw.phase == “ended” and
configDraw.state == “inProgress” then
configDraw.state = nil
display.remove(drawTable[#drawTable])
table.remove(drawTable, #drawTable)
end
end
function createDrawLines(draw)
– creates a second circle that will be used properly align the rectangle between the first and the second.
drawTable[#drawTable+1] = display.newCircle(cords.drawX,cords.drawY, configDraw.w)
drawTable[#drawTable]:setFillColor(0,0,255)
physics.addBody( drawTable[#drawTable], “kinematic”,{friction = 0, bounce = 0})
midPointX = (drawTable[#drawTable-1].x+drawTable[#drawTable].x)/2
midPointY = (drawTable[#drawTable-1].y+drawTable[#drawTable].y)/2
length =
math.sqrt(
math.abs(drawTable[#drawTable].x-drawTable[#drawTable-1].x)^2 +
math.abs(drawTable[#drawTable].y-drawTable[#drawTable-1].y)^2
)
+ configDraw.w
deltaX = drawTable[#drawTable].x-drawTable[#drawTable-1].x – used for calculating angle
deltaY = drawTable[#drawTable].y-drawTable[#drawTable-1].y – used for calculating angle
angle = math.atan2(deltaY,deltaX)*(180/math.pi) – radian angle converted to degrees using 180/pi
--removes old circle
display.remove(drawTable[#drawTable-1])
table.remove(drawTable, #drawTable-1)
table.insert(drawTable, 1, display.newRoundedRect(999,999,length,configDraw.w,configDraw.w/2))
drawTable[1].x = midPointX
drawTable[1].y = midPointY
drawTable[1].rotation = angle
drawTable[1]:setFillColor(30,10,10)
physics.addBody( drawTable[1], “static”,{friction = 0, bounce = 0})
end
screen = display.newRect(0,0,width,height)
screen.alpha = 0.5
screen:addEventListener(“touch”,startDraw)
-----===================================================================
physics = require( “physics” )
physics.setDrawMode( “hybrid” )
physics.start()
physics.setGravity(0,6)
gameBall = display.newCircle(320,50,16)
physics.addBody( gameBall, “dynamic”,{radius = 16, bounce = 0}) [/lua]