LoginSignup
2
2

More than 5 years have passed since last update.

縦置きのタイムバーをcocos2dで実装する。

Posted at
timebar.m
CCProgressTimer *time_bar = [CCProgressTimer progressWithSprite:[CCSprite spriteWithFile:@"timebar.png"]];
//タイムバーの生成を行う。

time_bar.percentage = 100.0;
//時間切れでゲームを止めるので初期値を100にする。

time_bar.type = kCCProgressTimerTypeBar;
//タイムバーのタイプレクタングルが他にある。

time_bar.barChangeRate = ccp(0, 1);
//バーをどの方向に変化させていくか。この場合y軸方向のみに変化する。

time_bar.midpoint = ccp(0.5f,0);
//どこから、バーを変化させるか。バーの上辺、の中心点から変化させるようにした。

[self addChild:time_bar];
//いつも通りにaddChild

[self schedule:@selector(timer) interval:0.01f];
//タイマーを呼んで、時間経過に合わせてバーを減らして行く。


-(void)timer {
        int seconds = 1;
        float speed = 1 / seconds;
        progress_timer.percentage -= speed;
        //分かりやすいように、秒ごとの変化値をいじればバーの進行早さを変えられるようにしてみた。

        if(progress_timer.percentage == 0) {
            [self unschedule:@selector(timer)];
            /* タイマーがゼロになったらタイマーを止める、ここでゲームを終了させるなどすれば
                タイマーを使ったゲームが作れる! うれしい。 */
        }
}

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2