我尝试使用[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];
我想要的是在透明背景下绘制的bezier路径。我的问题是,我无法弄清楚如何使图像背景透明。默认为白色。看来你必须告诉NSImage对某些内容进行复合添加,但我不能理解复合内容。
有这个:
[img drawInRect:frame fromRect:frame operation:NSCompositeSourceOver fraction:.5 respectFlipped:YES hints:nil];
但我不知道在哪里/如何使用它,因为它似乎没有自己做任何事情。
基本上我需要弄清楚如何创建一个NSImage,它实际上与从磁盘加载透明PNG一样。
谢谢!