=== Edited to add more information about the effect I'm trying to get ===
In an old screensaver, I'm drawing something like a comet: a bright object that leaves a fading trail of where it's been. So in each frame, I first draw over the whole screen with transparent black (alpha set to .02 or similar), then I draw the object at it's new location. (And of course in reality there are many of these "comets", 50 or so.)
6 or 8 years ago this worked fine on the Mac, but now in Mojave, although the fade is happening, it flickers wildly, as if the view is being erased to black before every drawRect call.
I'm just updating this old screen saver I wrote in 2010 or so, I'm very fond of it and it stopped working in Mojave. This fade technique worked fine back then, but something has apparently changed. I suspect something about the backing store or layers. I'm hoping for a bit of an education, pointers to relevant info, and suggestions on best practice for doing something like this.
(For the record, I was an active Mac programmer way back in the 90s - anyone remember develop magazine? - but rarely program now, so Cocoa and Objective C are still, ahem, "new" to me.)
The code is trivial. In my view's drawRect, before drawing any new stuff that is intended to fade out, I just do:
// Erase to black, but with much transparency, to fade out any previous drawing
[[NSColor colorWithDeviceRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.02] set];
[NSBezierPath fillRect: [self bounds]];
Again, I'm sure from digging around that this has something to do with views and layer backing, but I'm not sure of the best practice for fixing it, and I'd like to understand what I'm doing. Any pointers in the right direction are appreciated.
UPDATE: I found this question and answer that looks promising. Is it really necessary, though, to create my own offscreen image? I was hoping I could just set a boolean somewhere... :-)