I am trying to mask a node with SKCropNode class. I am doing it with my own init method in SKCropNode inherited class:
- (id)init {
self = [super init];
if (self) {
self.maskNode = [[SKSpriteNode alloc] initWithColor:[SKColor blackColor] size:(CGSize){50,50}];
SKSpriteNode *contentNode = [[SKSpriteNode alloc] initWithImageNamed:@"Spaceship"];
[self addChild: contentNode];
self.userInteractionEnabled = YES;
}
return self;
}
It works as expected:
Now, I want to add background to the scene and a cropped spaceship with following code:
-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
//
//background
//
SKSpriteNode * background = [SKSpriteNode spriteNodeWithImageNamed:@"background_game"];
background.position = CGPointMake(CGRectGetMidX(view.frame), CGRectGetMidY(view.frame) - CGRectGetMinY(view.frame));
[self addChild:background];
TurretCropNode * cropNode = [[TurretCropNode alloc] init];
cropNode.position = (CGPoint){view.frame.size.width/2,view.frame.size.height/2};
[self addChild:cropNode];
}
I have just added few lines with adding background at the beginning (cropped node lines remain the same)
Here what I got now:
Is it an expected behavior? Why cropped spaceship disappeared?
I am guessing that the image as shown below is your designated background. Have you checked your nodes
zPosition
?If you want to show your spaceship infront of your background, you will have to adjust the
zPosition
to be higher than that of the background sprite.