How could a line be drawn by the users finger to obstruct a moving object? I already have the code for the users finger drawing lines but I need to somehow “freeze” the line so the object can not pass it.
Hi @seananigan1. Welcome to the forums. Forum rules request that you do not post the same post multiple times. Please give the community some time to answer your post. I’ve removed your other duplicate of this post.
How are you making your lines?
Hi Rob,
I want to turn the lines to static for the physics engine. Here is the code:
local lineTable = {}
local lineWidth = 12
local lineColor = {R=math.random90,2550,G=math.random(0,255), B=math.random(0,255)}
local newLine = function(event)
local function drawLine()
local line = display.newLine(linePoints[#linePoints-1].x,linePoints[#linePoints-1].y,linePoints[#linePoints].x,linePoints[#linePoints].y)
line:setColor(lineColor.R, lineColor.G, lineColor. B);
line.width=lineWidth;
lineTable[i]:insert(line)
local circle = display.newCircle(linePoints[#linePoints].x,linePoints[#linePoints].y,lineWidth/2)
circle:setFillColor(lineColor.R, lineColor.G, lineColor. B)
lineTable[i]:insert(circle)
end
if event.phase==“began” then
i = #lineTable+1
lineTable[i]=display.newGroup()
display.getCurrentStage():setFocus(event.target)
local circle = display.newCircle(event.x,event.y,lineWidth/2)
circle:setFillColor(lineColor.R, lineColor.G, lineColor. B)
lineTable[i]:insert(circle)
linePoints = nil
linePoints = {};
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
elseif event.phase==“moved” then
local pt = {}
pt.x = event.x;
pt.y = event.y;
if not (pt.x==linePoints[#linePoints].x and pt.y==linePoints[#linePoints].y) then
table.insert(linePoints,pt)
drawLine()
end
elseif event.phase==“cancelled” or “ended” then
display.getCurrentStage():setFocus(nil)
i=nil
end
return true
end
local erase = function()
for i = 1, #lineTable do
lineTable[i]:removeSelf()
lineTable[i] = nil
end
return true
end
Runtime:addEventListener(“touch”,newLine)
This definitely helps. Can I use this template for one object rolling along the line
Hi @seananigan1. Welcome to the forums. Forum rules request that you do not post the same post multiple times. Please give the community some time to answer your post. I’ve removed your other duplicate of this post.
How are you making your lines?
Hi Rob,
I want to turn the lines to static for the physics engine. Here is the code:
local lineTable = {}
local lineWidth = 12
local lineColor = {R=math.random90,2550,G=math.random(0,255), B=math.random(0,255)}
local newLine = function(event)
local function drawLine()
local line = display.newLine(linePoints[#linePoints-1].x,linePoints[#linePoints-1].y,linePoints[#linePoints].x,linePoints[#linePoints].y)
line:setColor(lineColor.R, lineColor.G, lineColor. B);
line.width=lineWidth;
lineTable[i]:insert(line)
local circle = display.newCircle(linePoints[#linePoints].x,linePoints[#linePoints].y,lineWidth/2)
circle:setFillColor(lineColor.R, lineColor.G, lineColor. B)
lineTable[i]:insert(circle)
end
if event.phase==“began” then
i = #lineTable+1
lineTable[i]=display.newGroup()
display.getCurrentStage():setFocus(event.target)
local circle = display.newCircle(event.x,event.y,lineWidth/2)
circle:setFillColor(lineColor.R, lineColor.G, lineColor. B)
lineTable[i]:insert(circle)
linePoints = nil
linePoints = {};
local pt = {}
pt.x = event.x;
pt.y = event.y;
table.insert(linePoints,pt);
elseif event.phase==“moved” then
local pt = {}
pt.x = event.x;
pt.y = event.y;
if not (pt.x==linePoints[#linePoints].x and pt.y==linePoints[#linePoints].y) then
table.insert(linePoints,pt)
drawLine()
end
elseif event.phase==“cancelled” or “ended” then
display.getCurrentStage():setFocus(nil)
i=nil
end
return true
end
local erase = function()
for i = 1, #lineTable do
lineTable[i]:removeSelf()
lineTable[i] = nil
end
return true
end
Runtime:addEventListener(“touch”,newLine)
This definitely helps. Can I use this template for one object rolling along the line