【问题标题】:How to Combine SKTextures如何组合 SKTexture
【发布时间】:2014-04-15 17:54:55
【问题描述】:

我正在寻找一种将 SKTexture 组合在另一个 SKTexture 之上的方法,在外观上类似于在添加另一个带纹理的 SKSPritenode 作为子节点时的外观。我需要它是一个单一的 SKTexture 作为最终产品。

【问题讨论】:

  • 为什么两个精灵不够用?你可以使用 textureFromNode (或类似名称),它在 sk 类参考中
  • @LearnCocos2D - 从技术上讲,是不是可以用 alpha 属性纹理叠加多个节点来创建组合效果?还是我脑子放个屁……

标签: objective-c sprite-kit


【解决方案1】:

缺点是你做不到。一个 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 大小属性设置为 (maxWidth, maxHeight),这样就不会被剪裁。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多