0

我正在尝试在将SKLabelNode节点添加到自身后更改节点的文本。

这就是我在初始化时创建它的方式:

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */
        self.backgroundColor = [SKColor colorWithRed:0 green:0 blue:0 alpha:1.0];

        // Add label
        SKLabelNode *timeLabel = [SKLabelNode labelNodeWithFontNamed:@"timeLabel"];
        timeLabel.text = @"5";
        timeLabel.fontSize = 100;
        timeLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)+100);
        [self addChild:timeLabel];

    }
    return self;
}

如何更改其文本touchesBegan

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // Change label text?
}
4

1 回答 1

0

添加:

@property (nonatomic) SKLabelNode *timeLabel;

intWithSize:

-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
    /* Setup your scene here */
    self.backgroundColor = [SKColor colorWithRed:0 green:0 blue:0 alpha:1.0];

    // Add label
    self.timeLabel = [SKLabelNode labelNodeWithFontNamed:@"timeLabel"];
    self.timeLabel.text = @"5";
    self.timeLabel.fontSize = 100;
    self.timeLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)+100);
    [self addChild:self.timeLabel];

}
return self;
}

更改文本:

self.timeLabel.text = @"changeText";
于 2014-07-04T19:25:14.387 回答