Macos 来自NSImage的透明背景纹理

Macos 来自NSImage的透明背景纹理,macos,sprite-kit,transparency,nsimage,Macos,Sprite Kit,Transparency,Nsimage,我正在尝试使用[SKTexture textureWithImage:(NSImage*)]动态创建具有透明背景的Spritekit纹理 使用NSBezierPath绘制方法绘制纹理,如下所示: NSImage *img = [[NSImage alloc] initWithSize:frame.size]; [img lockFocus]; NSBezierPath *path = ... [path stroke]; // etc... [img unlockFocus]; SKTex

我正在尝试使用[SKTexture textureWithImage:(NSImage*)]动态创建具有透明背景的Spritekit纹理

使用NSBezierPath绘制方法绘制纹理,如下所示:

NSImage *img = [[NSImage alloc] initWithSize:frame.size];
[img lockFocus];

NSBezierPath *path = ...
[path stroke]; // etc...

[img unlockFocus];

SKTexture *tex =  [SKTexture textureWithImage:img];
SKSpriteNode *node = [SKSpriteNode spriteNodeWithTexture:tex];
[self.scene addChild:node];
我想要的是在透明背景下绘制贝塞尔路径。我的问题是我不知道如何使图像背景透明。默认为白色。似乎您必须告诉NSImage对某些内容进行附加合成,但我不理解对什么进行合成

这是:

[img drawInRect:frame fromRect:frame operation:NSCompositeSourceOver fraction:.5 respectFlipped:YES hints:nil];
但我不知道在哪里/如何使用它,因为它似乎没有自己做任何事情

基本上,我需要弄清楚如何创建一个NSImage,它与从磁盘加载一个透明PNG的效果相同

谢谢