亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SpriteKit-創建一個計時器

SpriteKit-創建一個計時器

白豬掌柜的 2019-06-24 09:30:27
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];     }}
查看完整描述

3 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

在SWIFT中可用:

var timescore = Int()  var actionwait = SKAction.waitForDuration(0.5)
            var timesecond = Int()
            var actionrun = SKAction.runBlock({
                    timescore++
                    timesecond++
                    if timesecond == 60 {timesecond = 0}
                    scoreLabel.text = "Score Time: \(timescore/60):\(timesecond)"
                })
            scoreLabel.runAction(SKAction.repeatActionForever(SKAction.sequence([actionwait,actionrun])))


查看完整回答
反對 回復 2019-06-24
?
森林海

TA貢獻2011條經驗 獲得超2個贊

我已經做了上面的快速例子,并為時鐘增加了前導零點。

    func updateClock() {
    var leadingZero = ""
    var leadingZeroMin = ""
    var timeMin = Int()
    var actionwait = SKAction.waitForDuration(1.0)
    var timesecond = Int()
    var actionrun = SKAction.runBlock({
        timeMin++
        timesecond++
        if timesecond == 60 {timesecond = 0}
        if timeMin  / 60 <= 9 { leadingZeroMin = "0" } else { leadingZeroMin = "" }
        if timesecond <= 9 { leadingZero = "0" } else { leadingZero = "" }

        self.flyTimeText.text = "Flight Time [ \(leadingZeroMin)\(timeMin/60) : \(leadingZero)\(timesecond) ]"
    })
    self.flyTimeText.runAction(SKAction.repeatActionForever(SKAction.sequence([actionwait,actionrun])))}


查看完整回答
反對 回復 2019-06-24
  • 3 回答
  • 0 關注
  • 815 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號