Created
July 22, 2013 00:46
-
-
Save AyatoKinkori/6050596 to your computer and use it in GitHub Desktop.
縦置きのタイムバーをcocos2dで実装する。 ref: http://qiita.com/ayahito2828/items/4efea78ec0b65adacb13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]; | |
/* タイマーがゼロになったらタイマーを止める、ここでゲームを終了させるなどすれば | |
タイマーを使ったゲームが作れる! うれしい。 */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment