简体   繁体   English

SpriteKit SKCropNode掩盖了一切

[英]SpriteKit SKCropNode Masks everything

I am trying to mask a node with SKCropNode class. 我试图用SKCropNode类掩盖一个节点。 I am doing it with my own init method in SKCropNode inherited class: 我正在用我自己的SKCropNode继承类中的init方法进行此操作:

- (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 ? 您是否检查过节点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. 如果要在背景zPosition显示太空飞船,则必须将zPosition调整为高于背景精灵的zPosition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM