Hi there. I’d be very grateful if someone with a little codea experience could explain to me why my example drawing class at https://gist.github.com/NerfedWar/5665580 has a flicker problem at the end of each line, only resolved when you start the next line.
I’m positive it’s just me being dim, just can’t get my head around it thus evening.
Cool project I’m playing around with it. I added backingMode(RETAINED) and it seemed to fix the flicker.
-- switch back to screen context and copy contents of canvas to it
noTint()
setContext()
blendMode(ADDITIVE)
backingMode(RETAINED)
background(0, 0, 0, 255)
spriteMode(CORNER)
sprite(self.canvas, 0, 0)
thanks Briarfox.
In case you are wondering, I’m drawing to an image buffer and not the actual screen as there will be lots of animation going on in other “layers” and I need to bring everything together each frame without losing the drawing. If I use retained mode to do this by blacking out the screen each frame, there is a significant performance hit.
I’m not really sure why there is any flickering at all.
@NerfedWar Yeah I saw the performance hit. I’m not that great of a graphics guy. Hopefully one of the other guys can figure it out. I’ll play with it some more though. The flickering is very odd.
.@NerfedWar Replace your DrawCanvas:draw with this code. I made a minor change.
function DrawCanvas:draw()
-- use screen context to obtain touch coordinates
setContext()
spriteMode(CENTER)
-- get the angle of the touch vector
px = CurrentTouch.prevX
py = CurrentTouch.prevY
dx = CurrentTouch.deltaX
dy = CurrentTouch.deltaY
dh = math.sqrt(dx*dx + dy*dy)
angle = math.atan2(dy, dx)
-- increment particle size as the line gets longer up to a m self.size = self.size self.step
self.size = self.size + self.step
psize = -1 * self.size * math.sin(math.log(self.size*self.size))
-- flip from increase to decrease
if(self.size>self.maxSize or self.size<self.minSize) then
self.step = self.step * - 1
end
-- switch to canvas and set color
setContext(self.canvas)
blendMode(ADDITIVE)
tint(self.penColor)
-- loop through each point of of dh vector adding particles so we get a relatively smooth line
nx = 0
ny = 0
if self.drawing then
for h = 0, dh, 2 do
ax = math.floor(h * math.cos(angle))
ay = math.floor(h * math.sin(angle))
nx = px+ax
ny = py+ay
-- draw onto canvas
--sprite("Dropbox:particle flare", nx, ny, psize, psize)
sprite(self.particle, nx, ny, psize, psize)
end
end
-- switch back to screen context and copy contents of canvas to it
noTint()
setContext()
blendMode(ADDITIVE)
background(0, 0, 0, 255)
spriteMode(CORNER)
sprite(self.canvas, 0, 0)
end
thanks dave. Can’t believe I missed that!