【问题标题】:SKLabelNode not showing up after disappearingSKLabelNode 消失后没有出现
【发布时间】:2014-03-15 22:17:21
【问题描述】:

所以我创建了一个 SKLabelNode: 编辑:将代码更改为: //。H {SKLabelNode *PausedLabel22;} //.m PausedLabel22= [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"]; PausedLabel22.text = @"游戏暂停"; PausedLabel22.fontSize = 30; PausedLabel22.fontColor = [SKColor blackColor]; PausedLabel22.position = CGPointMake(160, 340); //[self addChild:PausedLabel22]; 这曾经非常好,但后来我有了我的方法:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 if (paused == YES) {
    paused = NO;
    [PausedLabel22 removeFromParent];        
    NSLog(@"UnPaused");
}else if (touchLocation.x > self.frame.size.width - 80 && touchLocation.y > self.size.height-80 && touchLocation.y < self.size.height-40) {
    paused = YES;
    NSLog(@"Paused");    
    //PausedLabel22.text = [NSString stringWithFormat:@"Game Paused"];
    //PausedLabel22.fontColor = [SKColor blackColor];
    //PausedLabel22.position = CGPointMake(160, 320);
    [self addChild:PausedLabel22];
}
NSLog(@"Text Postion: (%f, %f)", PausedLabel22.position.x, PausedLabel22.position.y);
NSLog(@"Text: %@", PausedLabel22.text);
NSLog(@"Text color: %@", PausedLabel22.fontColor);

我的日志显示: 2014-03-15 23:12:12.734 核游戏[1418:60b] 未暂停 2014-03-15 23:12:12.735 NuclearGame[1418:60b] 文字位置:(160.000000, 320.000000) 2014-03-15 23:12:12.736 NuclearGame[1418:60b] 文字:游戏暂停 2014-03-15 23:12:12.737 NuclearGame[1418:60b] 文本颜色:UIDeviceRGBColorSpace 0 0 0 0 2014-03-15 23:12:13.248 核游戏[1418:60b] 暂停 2014-03-15 23:12:13.251 NuclearGame[1418:60b] 文字位置:(160.000000, 320.000000) 2014-03-15 23:12:13.252 NuclearGame[1418:60b] 文本:游戏暂停 2014-03-15 23:12:13.254 NuclearGame[1418:60b] 文本颜色:UIDeviceRGBColorSpace 0 0 0 1

但是,标签会出现在屏幕上(因为它在开始时被调用)然后消失得很好,但永远不会重新出现在屏幕上!

编辑:标签仍然没有出现......

【问题讨论】:

    标签: ios iphone sprite-kit sklabelnode


    【解决方案1】:

    我相信您没有看到它,因为您在 touchesBegan: 方法中在其自己的坐标系中将暂停标签的位置设置为 (160, 320),因此它会将其绘制到屏幕外。在其父节点坐标系中设置好位置后,无需再设置位置。

    将您的暂停标签节点命名为“pauseLabel”。该名称将用于检测是否在touchesBegan: 方法中触摸了该节点。

    //.h
    {SKLabelNode *PausedLabel22;}
    //.m
    PausedLabel22= [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
    PausedLabel22.name = @"pauseLabel";
    PausedLabel22.text = @"Game Paused";
    PausedLabel22.fontSize = 30;
    PausedLabel22.fontColor = [SKColor blackColor];
    PausedLabel22.position = CGPointMake(160, 340);
    [self addChild:PausedLabel22];
    

    开始接触:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
            for (UITouch *touch in touches) {
                SKNode *node = [self nodeAtPoint:[touch locationInNode:self]];
                if (node != self && [node.name isEqualToString:@"pauseLabel"]) {
                    if (paused == YES) {
                        paused = NO;
                        [PausedLabel22 removeFromParent];
                    } else {
                        paused = YES;
                        [self addChild:PauseLabel22];
                    }
                    return;
                }
            }
        }
    

    让我们知道这是否可行。

    这里还有一个用于在 spriteKit 中创建按钮的好类:https://stackoverflow.com/a/19199748/2526115

    【讨论】:

    • 谢谢,但它没有用,但 NSLogs 仍然认为一切正常,是否有可能通过在 touchesBegan 方法中添加一个子元素,它不会将它们添加到“顶层”层.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2016-01-31
    • 1970-01-01
    相关资源
    最近更新 更多