I’m making a simple prototype which draws a line between 2 objects which can be dragged around.
When each object is dragged I’d like each point on the line to update it’s position so that it matches the objects. My line will only ever have 2 points.
How do I access the x and y of each point on the line, once it has been created?
I’ve provided some drag and drop code below.
\_H = display.contentHeight;
\_W = display.contentWidth;
local function point1()
point1 = display.newRect (0,0,30,30)
point1:setFillColor(0,255,0)
point1.x = \_W / 2 - 100
point1.y = \_H / 2
function dragPlayer(event)
point1.x = event.x
point1.y = event.y
end
point1:addEventListener( "touch", dragPlayer )
end
local function point2()
point2 = display.newRect (0,0,30,30)
point2:setFillColor(0,255,0)
point2.x = \_W / 2
point2.y = \_H / 2
function dragPlayer(event)
point2.x = event.x
point2.y = event.y
end
point2:addEventListener( "touch", dragPlayer )
end
local function laserB()
local barrier = display.newLine(point1.x,point1.y,point2.x,point2.y)
barrier:setColor(0,0,255)
barrier.width = 5
end
local function lineMove()
--what do I put here to access the x and y of each point on line?
end
local function startGame()
point1()
point2()
laserB()
end
startGame()
Thanks in advance.
Dan [import]uid: 67933 topic_id: 24047 reply_id: 324047[/import]
