SKTexture from UIImage looks different

橙三吉。 提交于 2019-12-12 01:13:18

问题


I'm playing around with SpriteKit and I'm creating a SKTexture from an UIImage, then using SKSpriteNode to add the child to my SKScene (As a background), everything works fine, except that the UIImage looks very different from the original image, I tried to recreate the image in photoshop and the issue still remains, tested on Simulator and real device and different image colors, no changes.

The image format is PNG, and I added through Images.xcassets in Xcode 5

Image, results:

Different image, results:

I'm using the following code in my SKScene subclass:

- (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;
}

What I'm doing wrong?

Any help would be appreciated. :)


回答1:


Solution:

It was my fault, the image position was wrong, so I changed the position property:

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


来源:https://stackoverflow.com/questions/21765128/sktexture-from-uiimage-looks-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!