Multiple Balls on the screen

When I type this the object balls keep coming from the top left corner of the simulator? Could you show me where the problem is.

local physics = require(“physics”)

physics.start(true)

physics.setDrawMode()

local ball = display.newCircle(0, 10, 20)

ball:setFillColor(0, 100, 0)

physics.addBody(ball, “dynamic”, {bounce=0.3, radius=25, friction=0.5})

There is no problem, it’s how you wrote it. You created circle 20px wide with center in point (0, 10) so it is top left corner of screen. Maybe you thought (0, 0) is in bottom left corner? If so , let me correct you. On all types of digital screens (phones, computers, tvs) point (0, 0) is always in top left corner. X axis is directed right and Y axis is directed toward the bottom of screen.

Thank you for the information, but I still don’t understand why when the user starts to draw a line, 30 balls appear from the top left. 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 physics = require(“physics”)

physics.start()

physics.setDrawMode(“normal”)

local ball = display.newCircle(0, 100, 20)

ball:setFillColor(0, 100, 0)

physics.addBody(ball, “dynamic”, {bounce=0.3, radius=10, friction=0.5})

physics.addBody(line, “static”, { bounce= -1, density=0.3, friction=0.7, shape = lineshape})

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)

There is no problem, it’s how you wrote it. You created circle 20px wide with center in point (0, 10) so it is top left corner of screen. Maybe you thought (0, 0) is in bottom left corner? If so , let me correct you. On all types of digital screens (phones, computers, tvs) point (0, 0) is always in top left corner. X axis is directed right and Y axis is directed toward the bottom of screen.

Thank you for the information, but I still don’t understand why when the user starts to draw a line, 30 balls appear from the top left. 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 physics = require(“physics”)

physics.start()

physics.setDrawMode(“normal”)

local ball = display.newCircle(0, 100, 20)

ball:setFillColor(0, 100, 0)

physics.addBody(ball, “dynamic”, {bounce=0.3, radius=10, friction=0.5})

physics.addBody(line, “static”, { bounce= -1, density=0.3, friction=0.7, shape = lineshape})

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)