ios - 来自 UIImage 的 SKTexture 看起来不同

标签 ios uiimage sprite-kit skspritenode sktexture

我正在玩弄 SpriteKit,我正在从 UIImage 创建 SKTexture,然后使用 SKSpriteNode 将 child 添加到我的 SKScene(作为背景),一切正常,除了 UIImage 看起来与原始图像,我尝试在 photoshop 中重新创建图像,但问题仍然存在,在模拟器和真实设备以及不同的图像颜色上进行测试,没有变化。

图片格式为PNG,我在Xcode 5中通过Images.xcassets添加

图片、结果:

enter image description here

不同的图像,结果:

enter image description here

我在我的 SKScene 子类中使用以下代码:

- (id)initWithSize:(CGSize)size
{

    if (self = [super initWithSize:size]) {

        SKTexture *textureGradient = [SKTexture textureWithImage:[UIImage imageNamed:@"Image"]];
        SKSpriteNode* spriteGradient = [SKSpriteNode spriteNodeWithTexture:textureGradient];
        [self addChild:spriteGradient];

    }
    return self;
}

我做错了什么?

如有任何帮助,我们将不胜感激。 :)

最佳答案

解决方法:

这是我的错,图像位置错误,所以我更改了position属性:

SKTexture *textureGradient = [SKTexture textureWithImage:[UIImage imageNamed:@"Image"]];
SKSpriteNode* spriteGradient = [SKSpriteNode spriteNodeWithTexture:textureGradient];
spriteGradient.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
[self addChild:spriteGradient];

关于ios - 来自 UIImage 的 SKTexture 看起来不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21765128/

相关文章:

ios - 如果我不需要持久存储,那么以类似数据库的方式存储数据的最佳做法是什么? NSMutableArray?

ios - 具有可调整大小的图像的 UIButton

iOS UIImage 转换为固定内存大小

ios - 使用 flatMap 枚举 SpriteKit 节点

swift 2 : Removing Slowly increase of speed

ios - 如何使用 Swift 2 (SpriteKit) 以编程方式添加要查看的对象?

ios - 如何在 swift 中将月份名称数组转换为月份编号

iOS - 查看旋转和调整大小

ios - 在 Label 中显示整数值,int 到 String 转换?

iOS Facebook 4.0 SDK Share OpenGraph 故事与 UIImage 错误