hi guys, I’m using this code to let the player draw a line, the problem is that I want that appear a rect line instead of a curved line, how can I do this? Here’s the code I’ve used.
require("physics")
physics.start()
physics.setDrawMode("normal")
local HEIGHT = display.contentHeight
local WIDTH = display.contentWidth
display.setStatusBar( display.HiddenStatusBar )
local lines = {}
local line\_number = 1
local line\_width = 10
local prev\_x, prev\_y, ball
local function draw\_line(e)
if e.phase == "began" then
prev\_x = e.x
prev\_y = e.y
elseif e.phase == "moved" then
lines[line\_number] = display.newLine(prev\_x, prev\_y, e.x, e.y)
lines[line\_number]:setColor(math.random(255), math.random(255), math.random(255))
lines[line\_number].width = line\_width
dist\_x = e.x - prev\_x
dist\_y = e.y - prev\_y
physics.addBody(lines[line\_number], "static", { density = 1, friction = 0.5, bounce = -1.0, shape = {0, 0, dist\_x, dist\_y, 0, 0} } )
prev\_x = e.x
prev\_y = e.y
line\_number = line\_number + 1
elseif e.phase == "ended" then
end
end
new\_ball\_button = display.newRect(10, HEIGHT - 75, 150, 75)
delete\_lines\_button = display.newRect(WIDTH - 150, HEIGHT - 75, 150, 75)
local leftWall = display.newRect(0, 0, 1, display.contentHeight)
local rightWall = display.newRect(display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect(0, 0, display.contentWidth, 1)
physics.addBody(leftWall, "static", {bounce = 0.1})
physics.addBody(rightWall, "static", {bounce = 0.1})
physics.addBody(ceiling, "static", {bounce = 0.1})
function new\_ball\_button:touch(e)
if e.phase == "ended" then
ball = display.newCircle(50, 50, 25)
physics.addBody(ball, {density = 5000, friction = 0.5, bounce = 1.0, radius = 25} )
ball:setFillColor(255,0,0)
end
end
function delete\_lines\_button:touch(e)
if e.phase == "ended" then
for i = #lines, 1, -1 do
if (lines[i]) then
lines[i].parent:remove(lines[i])
lines[i] = nil
end
end
lines = {}
line\_number = 1
end
end
Runtime:addEventListener("touch", draw\_line)
new\_ball\_button:addEventListener("touch", new\_ball\_button)
delete\_lines\_button:addEventListener("touch", delete\_lines\_button)
Thanks!
[import]uid: 129238 topic_id: 23321 reply_id: 323321[/import]