0

I adapted Apple's RoundTransparentWindow sample project to create a NSWindow and NSView which I use to have a transparent window (obviously the children of the NSView are visible, just not the window or the view's background).

I would like to add a CAEmitterLayer for particle effects to this window, but as soon as I set the view to layer backed (which seems to be a requirement of CAEmitterLayer) with

    self.view.wantsLayer    = true 

the view loses its transparency and becomes opaque.

How can I have a transparent, layer-backed NSWindow? Or, is it possible to use CAEmitterLayer in some other way on a transparent window?

glenstorey
  • 5,134
  • 5
  • 39
  • 71
  • `CAEmitterLayer` will work with a transparent window if you create a custom view for it. – l'L'l May 24 '16 at 03:17
  • That's encouraging! I'm using a custom view at the moment based on the one used in `RoundTransparentWindow`: https://developer.apple.com/library/mac/samplecode/RoundTransparentWindow/Listings/Classes_CustomView_m.html#//apple_ref/doc/uid/DTS10000401-Classes_CustomView_m-DontLinkElementID_6 , but I must be doing something wrong. Can you unpack what the custom view needs? – glenstorey May 24 '16 at 03:21
  • I uploaded a [quick project](https://github.com/dylib/Fire) for you to play with ... (it's definitely not perfect, although it should give you some idea on how a CAEmitterLayer can be used within a transparent window). :) – l'L'l May 24 '16 at 04:18
  • Thanks so much! Looking forward to checking it out. Just glad that it's possible. Thought it might be too "edge case" – glenstorey May 24 '16 at 04:23
  • 1
    You're welcome! ... I'm total edge case, so you're talking to the right guy. I also cleaned up the project a bit just now (removed redundant AppDelegate, etc.). If you have more questions just let me know. – l'L'l May 24 '16 at 04:39
  • That worked, thanks so much! Specifically this is what I was missing for a layer-backed view (converted to swift). In fact I could drop a lot of the sample Apple code, including the drawRect call that was in RoundTransparentView. let thisWindow = animationWindowController?.window thisWindow?.opaque = false thisWindow?.backgroundColor = NSColor(deviceWhite: 0.0, alpha: 0.0). animationWindowController?.showWindow(self) Do you want to pop that in an answer so I can mark it as correct? Thanks again! – glenstorey May 24 '16 at 17:39

0 Answers0