0
votes

I am creating a game in SpriteKit and having trouble using background images in my game. I think the problem is that the image has to be the exact resolution of the device otherwise it won't show up. My game is universal so I need it to work with all devices and screen sizes. The way it is now the background shows up black on every device except a normal resolution iPad. I believe this is because that is the resolution of the image. So I want to add on an image that is the resolution of an iPhone but i don't know how to name it so that it would work. How would I go about this? Thanks!

- (void)didMoveToView:(SKView *)view
{
    if (!self.contentCreated)
    {
        [self createSceneContents];
        self.contentCreated = YES;
    }
}

- (void)createSceneContents
{
    self.backgroundColor = [SKColor whiteColor];
    self.scaleMode = SKSceneScaleModeAspectFill;



    SKSpriteNode *bgImage = [SKSpriteNode spriteNodeWithImageNamed:@"bg"];
    [bgImage setAnchorPoint:CGPointZero];
    [self addChild:bgImage];
}

For some reason it only works on a non retina iPad the screen shows up black on all others

1
Having the wrong resolution doesn't cause an image to just not show up. Something else must be wrong. Show your code. - Mick MacCallum
@0x7fffffff I updated it - ZB-dev

1 Answers

0
votes

Essentially this is all you need...

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

        // make your background here i.e.
        _background = [SKSpriteNode spriteNodeWithImageNamed:@"bg"];
        [_background setAnchorPoint:CGPointZero];
        [self addChild:_background];

    }
    return self;
}