プログラマメモ2 - programmer no memo2

admobです。iosで使うときデフォルトのプロジェクトだとLinkedフレームワーとライブラリがたりないので足すことを忘れずに。 2012/04/28
2012/05/24

admobです。iosで使うときデフォルトのプロジェクトだとLinkedフレームワーとライブラリがたりないので足すことを忘れずに。

参考 Google AdMob Ads iOS(初級) - Google AdMob Ads SDK — Google Developers

cocos2dで使用しているとこんな感じ。
MessageUIとSystemConfigurationが足りなかった。

追記 2012/05/24 AudioToolbox.frameworkも何やら必須のようです。

cocos2dでscoreとかの更新,ようするにラベルの文字列をあとから更新ってことです。 2012/04/23

cocos2dです。
スコアとかupdateメソッドで更新とかしたい場合を想定しております。
下記参考リンク
cocos2dで文字列の更新 « なんかもう実験場
タグで検索して使うというのが自分好みかな。
はじめ

{ // score CCLabelTTF *lblScore = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"SCORE:%d",0] fontName:@"Arial" fontSize:32.0]; lblScore.color = ccc3(0,0,0); lblScore.tag = 6000; CGPoint point = ccp(90, 450); lblScore.position = point; [self addChild:lblScore]; }

書き換え

CCLabelTTF *lblScore = (CCLabelTTF*)[self getChildByTag:6000]; [lblScore setString: [NSString stringWithFormat:@"SCORE:%d", スコア]];

ようやくcocos2dを使うことになれてきた感じがするなー

スプラッシュ? 2012/04/21

なんか全然自信がないんですよね。
cocos2dです。
ゲームとかでスタートするときに1、2、3とかで使うやつをイメージしてつくってみました。 ひとつのスプライトがおわったら次をよぶという感じです。イメージファイルを文字列指定してスプライトを配列分つくる感じ。
ふー
どうだろう。 あと音素材は 音楽素材/魔王魂さんのものを使ってたりします。
グラフィックとか音とか、ゲームにはかかせない要素ですものね。


/* また微妙な気がするが使えるかな- */ - (void) splash:(int)cnt arr:(NSMutableArray*)arr finalBlock:(id)finalBlock{ CGSize size = [[CCDirector sharedDirector] winSize]; { // int max = [arr count]; if(!(cnt < max)){ // 最後に実行する CCNode *dummy = [CCNode node]; [self addChild:dummy]; id remove = [CCCallBlock actionWithBlock:(^{ [dummy removeFromParentAndCleanup:YES]; })]; id seq = [CCSequence actions:[CCDelayTime actionWithDuration:0], finalBlock, remove, nil]; [dummy runAction: seq]; return; } CCSprite *sprite = [CCSprite spriteWithFile:[arr objectAtIndex:(NSInteger)cnt]]; cnt = cnt + 1; sprite.position = ccp( size.width /2 , size.height/2 ); [self addChild:sprite]; { // アニメーション // 効果音 id sound = [CCCallBlock actionWithBlock:(^{ SimpleAudioEngine *audioEngine = [SimpleAudioEngine sharedEngine]; [audioEngine playEffect:@"se_maoudamashii_onepoint14.mp3"]; })]; id fadeto = [CCSpawn actions: [CCFadeTo actionWithDuration:1.0 opacity:0], nil]; id scaleBy = [CCScaleBy actionWithDuration:1.0f scale:3.0f]; id action = [CCSpawn actions:sound, fadeto, scaleBy, nil]; id ease = [CCEaseInOut actionWithAction:action rate:3.]; id remove = [CCCallBlock actionWithBlock:(^{ [sprite removeFromParentAndCleanup:YES]; [self splash:cnt arr:arr finalBlock:finalBlock]; })]; id seq = [CCSequence actions:[CCDelayTime actionWithDuration:0], ease, remove, nil]; [sprite runAction: seq]; } } }// end

CCProgressTimerの実装例 2012/04/21

cocos2dです。
CCProgressTimerの実装例です。

CCProgressTimer *timer = [CCProgressTimer progressWithSprite:[CCSprite spriteWithFile:@"Icon.png"]]; // timer.type = kCCProgressTimerTypeRadial; // timer.type = kCCProgressTimerTypeBar; timer.percentage = 0; timer.position = ccp(size.width/2,size.height/2); [self addChild:timer z:1 tag:123]; [self scheduleUpdate];
updateの実装はこんな感じ?
-(void)update:(ccTime)dt { //progress bar CCNode* node = [self getChildByTag:123]; CCProgressTimer *timer = (CCProgressTimer*)node; timer.percentage += dt * 10;// 1sec? if (timer.percentage >= 100) {// 10sec? timer.percentage = 0; } }

kCCProgressTimerTypeRadialは以下

kCCProgressTimerTypeBarは以下

CCLayerColorは背景色をかえたいときに使えます。 2012/04/21

cocos2dです。
CCLayerColorは、背景色をまっしろにしたいときに使えます。

CCLayerColor *colorLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)]; [self addChild:colorLayer];


ちなみにccc4ってなんだろうということで下記
//! helper macro that creates an ccColor4B type static inline ccColor4B ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o) { ccColor4B c = {r, g, b, o}; return c; }

「懸垂やろうぜ!」リリース.....Orz.. 2012/04/17
2012/04/21

App Store - 懸垂やろうぜ!をリリースしました。
単純に懸垂したら手動で回数を記録するというアプリです(笑)。また微妙なものをつくった感でいっぱいです。
技術的には、はじめてCore Dataを使ってみました。あとStoryBoardも使ってみました。iOS5用で、ARC使ってます。使う分には全然関係ないものですが。
2012/4/21 追記
ううう、壊滅的にダウンロードされない(10回以内...)
いい勉強になりました(笑)