相关疑难解决方法(0)

SpriteKit - 创建一个计时器

我怎样才能创建一个每两秒触发一次的计时器,它会在我屏幕上的HUD上将分数增加一个?这是我对HUD的代码:

    @implementation MyScene
{
    int counter;
    BOOL updateLabel;
    SKLabelNode *counterLabel;
}

-(id)initWithSize:(CGSize)size
{
    if (self = [super initWithSize:size])
    {
        counter = 0;

        updateLabel = false;

        counterLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
        counterLabel.name = @"myCounterLabel";
        counterLabel.text = @"0";
        counterLabel.fontSize = 20;
        counterLabel.fontColor = [SKColor yellowColor];
        counterLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;
        counterLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeBottom;
        counterLabel.position = CGPointMake(50,50); // change x,y to location you want
        counterLabel.zPosition = 900;
        [self addChild: counterLabel];
    }
}
Run Code Online (Sandbox Code Playgroud)

timer objective-c ios sprite-kit

29
推荐指数
3
解决办法
1万
查看次数

标签 统计

ios ×1

objective-c ×1

sprite-kit ×1

timer ×1