Well to clarify, actually my task was a bit different than drawing polygon animations. What I wanted to do was to let the user draw something on the screen, so I start with a bit of a line which then grows to a longer set of lines. I did have the same flickering base issue though, for which the workaround described above helped.
As it’s integrated in my little sprites framework the code below isn’t copy and paste ready but maybe it gets across the idea. The following is inside the canvas sprite’s “handle” function, and the canvas sprite is set to listenToTouch = true and sets self.data.lines = {}:
[code]local framesToWaitBeforeRecordingPoint = 2
local maxPointsPerDrawing = 250
if self.action.touched then
if self.phase.name == ‘default’ then
if self.action.touchJustBegan then
self.data.lines[#self.data.lines + 1] = {}
end
if not self.phase:isInited() then
self.phase:set(‘drawPause’, framesToWaitBeforeRecordingPoint, ‘default’)
end
if self.data.pointsCount <= maxPointsPerDrawing then
local line = self.data.lines[#self.data.lines]
local isSufficientlyNewPosition = true
if #line >= 2 then
local distance = misc.getDistance( {x = self.touchedX, y = self.touchedY}, {x = line[#line - 1], y = line[#line]} )
isSufficientlyNewPosition = distance >= 10
end
if isSufficientlyNewPosition then
self.data.pointsCount = self.data.pointsCount + 2
line[#line + 1] = self.touchedX
line[#line + 1] = self.touchedY
if #line >= 4 then
local lastPoints = {line[#line - 3], line[#line - 2], line[#line - 1], line[#line - 0]}
app.spritesHandler:createLine(‘temporaryDrawingIndicator’, lastPoints, nil, self.id)
end
if #line >= 2 then
app.spritesHandler:createCircle(‘temporaryDrawingIndicator’, line[#line - 1], line[#line - 0], app.canvasStrokeWidth / 2, nil, self.id)
end
if self.data.pointsCount > maxPointsPerDrawing then self.phase:set(‘suppressFurtherPoints’) end
end
end
end
end[/code]
When the user is finished drawing using above it results in the self.data.lines array, which is a set of lines that can be drawn using display.newLine and append. [import]uid: 10284 topic_id: 4905 reply_id: 26745[/import]