Fellow Coronians, I need your help once again. The issue I am having is a very illusive one. I am drawing on a background as in coloring the background with different colors. I used the drawLine tutorial. The issue I am having is:
When I zoom in and color or draw a line and then zoom back out. The line does not stay with the image I am coloring. Also if I color zoomed out, when I zoom in the line or colors do not stay in position. I think it has to do with the event.x and event.y properties. I have both line and image in two different groups. I am then using xScale and yScale to scale both equally. Any help from the community would be most appreciated. Thank you
Code I am using below. I got the line coloring code from Code Exchange and I only made slight modification to it.
[lua]local lineTable = {}
– This is a required table that will contain each drawn line as a separate display group, for easy referral and removal
local r = 0
local g = 0
local b = 0
local lineWidth = 12 – fixed for now – was 24
–local lineColor = {R=math.random(0,255), G=math.random(0,255), B=math.random(0,255)}
local lineColor = {R = r, G = g , B = b}
– Also for random colors. Maybe we want a magic marker?
–local lineColor = {R=0, G=0,B=0}
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, 240);
line.width=lineWidth;
lineTable[i]:insert(line)
crayonGroup: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)
crayonGroup:insert(circle)
end – END Drawline
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, 240)
lineTable[i]:insert(circle)
crayonGroup: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
paintCanvas:addEventListener(“touch”,newLine)
[/lua]
And I am scaling with this:
[lua]local zoomBG = display.newRect(0,20,40, 50)
zoomBG:setFillColor(100,100,100)
localGroup:insert(zoomBG)
local zoomIn = display.newImageRect(“images/zoomIn.png”, 60,60)
zoomIn.x,zoomIn.y = 20, 33
zoomIn.xScale, zoomIn.yScale = .5,.5
localGroup:insert(zoomIn)
local zoomOut = display.newImageRect(“images/zoomOut.png”, 60,60)
zoomOut.x,zoomOut.y = 20, 57
zoomOut.xScale, zoomOut.yScale = .5,.5
localGroup:insert(zoomOut)
local function zoomImage()
for i = 1, zoomGroup.numChildren do
zoomGroup[i].xScale = 1.6
zoomGroup[i].yScale = 1.6
end
for i = 1, crayonGroup.numChildren do
crayonGroup[i].xScale = 4.6
crayonGroup[i].yScale = 4.6
end
end
zoomIn:addEventListener(“touch”, zoomImage)
local function zoomOutImage()
for i = 1, zoomGroup.numChildren do
zoomGroup[i].xScale = 1.0
zoomGroup[i].yScale = 1.0
end
for i = 1, crayonGroup.numChildren do
crayonGroup[i].xScale = 1.0
crayonGroup[i].yScale = 1.0
end
end
zoomOut:addEventListener(“touch”, zoomOutImage) [/lua] [import]uid: 53149 topic_id: 33626 reply_id: 333626[/import]