Background image size Sprite Kit Game

后端 未结 9 2002
一生所求
一生所求 2020-12-23 09:51

i just started a new Sprite Kit project to learn how to use it. I watched and read a lot of tutorials but no tutorial has a answer for my question/problem.

I want to

9条回答
  •  伪装坚强ぢ
    2020-12-23 10:32

    I've found that if an image is not the same size as the node you are looking to create the sizing gets a little funny (say using a retina image on a non-retina device or incorrect image naming). You can scale the image to fill if you create the texture from the image and set the texture and the node size using something like the following:

    SKTexture *backgroundTexture = [SKTexture textureWithImageNamed:@"MyImage.png"];
    SKSpriteNode *background = [SKSpriteNode spriteNodeWithTexture:backgroundTexture size:self.view.frame.size];
    background.position = (CGPoint) {CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame)};
    [scene addChild:background];
    

    I'm not a 100% sure this if this will fix your issue or not but it might be worth a shot.

提交回复
热议问题