我正在为移动设备制作纹身绘图游戏。玩家必须用手指在纹身上画填充物。在那里,我必须放置一个进度条,它将显示玩家颜色填充了多少区域。我该如何追踪进度?这个进度条可以使用近25个纹身。所以我需要一种通用技术。
答案 0 :(得分:0)
以下是我编写的一些可能对您有帮助的源代码:
local endPoint, startPoint
local lines, line, lx, ly, sx, sy = {}
local points = {}
r,g,b = 255,0,0
lineWidth = 10
local drawPacket
local odd = true
local function draw(event)
if event.phase == "began" then
startPoint = display.newCircle(0,0,lineWidth/2)
startPoint.x, startPoint.y = event.x, event.y
startPoint:setFillColor(r,g,b)
if startPoint.x <350 or startPoint.x > 700 then
director:changeScene("fail")
end
endPoint = display.newCircle(-100,0,lineWidth/2)
endPoint:setFillColor(r,g,b)
lineGroup:insert(startPoint)
lineGroup:insert(endPoint)
elseif event.phase == "moved" then
if not line then
print "I am now drawing the line"
line = display.newLine(startPoint.x, startPoint.y, event.x, event.y)
lines[ #lines + 1 ] = line
line.width = lineWidth
line:setColor(r,g,b)
lx,ly = startPoint.x , startPoint.y
sx,sy = event.x, event.y
lineGroup:insert(line)
else
if math.sqrt((lx-event.x)^2+(ly-event.y)^2) > 2 then
--print "I am now appending the line"
line:append( event.x, event.y)
lx, ly = event.x, event.y
end
endPoint.x = event.x
endPoint.y = event.y
if odd then
points[#points+1] = event.x
points[#points+1] = event.y
end
odd = not odd
end
elseif event.phase == "ended" then
if win == true then
if endPoint.x <350 or endPoint.x > 700 then
director:changeScene("fail")
else
director:changeScene("scene11")
end
else
director:changeScene("fail")
end
line = nil
endPoint.x, endPoint.y = event.x, event.y
print "I have ended my touch, sending data"
points = {}
end
end
background:addEventListener("touch", draw)
确保将“背景”替换为您希望用户“纹身”的图像。祝你的项目好运。