我正在寻找一种将 SKTexture 组合到另一个 SKTexture 之上的方法,其外观类似于添加另一个纹理 SKSPritenode 作为子节点时纹理 SKSpritenode 的外观。我需要它成为一个单一的 SKTexture 作为最终产品。
最佳答案
缺点是你做不到。一个 SKSpriteNode 只能采用一个 SKTexture。在 SpriteKit 框架中执行此操作的唯一方法是在父节点之上添加子节点。
另一种方法是使用一系列图像并将它们组合起来,然后将最终产品作为纹理添加到 Sprite 节点。
CGSize mergedSize = CGSizeMake(maxWidth, maxHeight); // <- use the largest width and height for your images if they are different sizes
UIGraphicsBeginImageContextWithOptions(mergedSize, NO, 0.0f);
[textureImage1 drawInRect:CGRectMake(0, 0, maxWidth, textureImage1.size.height)];
[textureImage2 drawInRect:CGRectMake(0, 0, 75, textureImage2.size.height)];
// ... add any additional images ...
UIImage *mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.texture = [SKTexture textureWithImage:mergedImage];
确保将 SKSpriteNode 大小属性设置为 (maxWidth, maxHeight),这样就不会剪切任何内容。
关于objective-c - 如何组合 SKTextures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23091001/