1
votes

EDIT: I must have just been on crack earlier. Clean and another rebuild seems to have fixed it.

I'm hoping a second set of eye on this will tell me what I'm missing. I have SpriteKit game scene (iOS 7.1) with a couple of "HUD" SKSpriteNodes... mute sounds button, show last score, etc. I'm detecting if they're touched in touchesBegan:withEvent.

When the node is touched a corresponding method is called to display it's content (this part is working fine). They aren't SKScenes just a SKSpriteNode image with some labels over top. One of the labels is a Back Button which I want to close the node/remove it from parent. This isn't working as I expect it should.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint touchLocation = [touch locationInNode:self];
    SKNode *touchedNode = [self nodeAtPoint:touchLocation];

    // --- Scores

    if ([touchedNode.name isEqualToString:@"scoresButton"]) {
        [self showScoresBoard];
    }

    // --- Back

    if ([touchedNode.name isEqualToString:@"backLabel"]) {
        SKNode *chalkboard = [self childNodeWithName:@"chalkboard"];
        NSLog(@"Touched: %@", touchedNode.name); // backLabel shows in display
        // chalkboard.alpha = 0.0; // Oddly, this works :/
        [chalkboard removeFromParent]; // This does not work ?
    }
}

My showScoresBoard is pretty standard stuff...

-(void)showScoresBoard {
    // Root Node
    SKNode *chalkboard = [SKNode node];
    chalkboard.name = @"chalkboard";

    // [Background, labels...]

    // Back Label
    SKLabelNode *backLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];

    backLabel.name = @"backLabel";
    backLabel.text = @"Back";
    backLabel.fontColor = [UIColor whiteColor];
    backLabel.fontSize = 22;
    backLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - 165);
    backLabel.zPosition = 150;

    [chalkboard addChild:backLabel];

    [self addChild:chalkboard];
}

So I guess my question is, why isn't "[chalkboard removeFromParent]" doing anything? What am I missing there? It must being seeing the SKNode correctly as changing it's alpha property works.

Any thoughts?

2
Does any kind of error occur or does this method not get called at all? - ZeMoon
No errors... and if I put an NSLog in before the removeFromParent does produce output so I know it's making it there. - Chris Sprague

2 Answers

0
votes

Seriously not sure exactly why it's working now. Only thing I did before revisiting the issue is do a clean and build after working on another section of the project. Must have been some stray bits that the clean took care of.

0
votes

[self.parent removeFromParent]; may be work