Since currently it is not possible to set the color to of a SKScene
to clearColor
, by doing
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor clearColor];
}
return self;
}
As seen here: LINK
Then how can one set the background image for a SKScene
? Please be as specific as possible, sample code would be great!
swift 4 version:
let background = SKSpriteNode(imageNamed: "CheckIcon")
background.size = frame.size
background.position = CGPoint(x: frame.midX, y: frame.midY)
addChild(background)
Use an SKSpriteNode
centered in the scene:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
// Replace @"Spaceship" with your background image:
SKSpriteNode *sn = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
sn.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
sn.name = @"BACKGROUND";
[self addChild:sn];
}
return self;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With