如何结合SKTextures

时间:2014-04-15 17:54:56

标签: objective-c sprite-kit

我正在寻找一种方法将SKTexture结合在另一个SKTexture之上,外观与纹理SKSpritenode在添加另一个纹理SKSPritenode作为孩子时的外观相似。我需要它作为单个SKTexture作为最终产品。

1 个答案:

答案 0 :(得分:3)

缺点是你无法做到。 SKSpriteNode只能使用一个SKTexture。在SpriteKit框架中执行此操作的唯一方法是在父节点之上添加子项。

另一种方法是使用一系列图像并在将最终产品作为纹理添加到精灵节点之前将它们组合。

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 size属性设置为(maxWidth,maxHeight),以便不会剪切任何内容。