2009年6月4日木曜日

NSTimer

現在考えているのは、時間を制限してカウントダウンさせるというもの。
自身の勉強の為と割り切って拡張させようと思う。

今回はNSTimerを使う。

- (void)viewDidLoad {
[super viewDidLoad];
timer = [NSTimer scheduledTimerWithTimeInterval:(0.1)
target:self selector:@selector(onTimer:)
userInfo:nil repeats:YES];
}

この場合だと0.1秒感覚でカウントアップさせるメソッドとなり、
目的に応じて変更させる必要がある。
また、実行させる為にボタンを追加させるということはせずに
アプリの起動と同時にタイマーを起動させるのが目的。

いよいよ本日、WWDC2009に出席する為
サンフランシスコへ向けて、出発。


2009年5月27日水曜日

ゼミ seminar

本日はゼミで中間報告があり、
座標指定についてのコード説明を行なった。

シャッフルさせないでカードを表示させた場合(図1)
の座標について聞かれた際に、座標の数値が
上方向に増えるものとして答えてしまったが、
後で確認してみると、「下方向に増える」ということが
chapter11で図2と合わせてしっかりと説明されていることが分かった。
まだまだ解析が不十分だと感じた。

Today,i explained the code of coordinates in a seminar.

i was asked a question bout the coodinate
when the card id displayed without shuffling,(Figure1)
i answered the number of coordinates increases for above.
But I found that "Increase below" 
by explaining chapter11 with Figure 2.
i was felt that make an analysis of the code is still insufficient for me.


   図1(Figure 1)     



     図2(Figure 2)
     

2009年5月26日火曜日

枚数変更  change the number of sheets

枚数を変更させる為に、Model.mとController.mの変更を行なった。
以下はModel.mのカードを配り直す処理。
枚数を16枚(4×4)から36枚(6×6)にしたいので、3行目の数字を36に変更。
To change the number of sheets, i made change to the Model.m and Controller.m .
The following method shows about process that starts dealing the card of Model.m.
The number of sheets of the third line changed to 36.


- (void)resetCards {
[cards release];
[self setupCards:36];


続いて、Comtroller.mを変更。
Next, i changed Comtroller.m.


- (void)initController {
srandom( abs( time( nil ) ) );
[self loadImages];
int x, y;

for ( y = 0; y < 6; y++ )

{

for ( x = 0; x < 6; x++ )

{

  CGRect bounds = CGRectMake(0, 3, 50, 50 ); 
          bounds = CGRectOffset( bounds, x * 54, y * 55); 
      CardView *button = [[[CardView alloc]     
          initWithFrame:bounds] autorelease]; 
          [button setTarget:self]; 
          [button setIndex:x + y * 6];  
          [view addSubview:button]; 
        }
 } 
[model readScoreData]; 
[model setupCards:36]; 
[self syncModelToView]; 


5・7行目(line) 
計36回ループさせたいので4を6に変更。
 Method of loop 36 times in total. 


9行目(line) X座標、Y座標、幅、高さを、変更。 
直角4辺形の構造体の設定を行う。
 Changing the X coordinates, Y coordinates, width, and height. 
Setting of ectangular structure. 


10行目(line) 
変数boundsの原点の移動を表す。
 9・10行目のメソッドで数字の調整をする必要がある。
図1は修正前。
 This method shows movement an origin of bounds.
 If the figure is not adjusted, its displayed as Figure 1. 


14行目(line)
 tagに番号を決める。 
アクションメソッド内で押された番号を識別できるようにする。
 これによって、
図2のように 1クリックで2枚表示される等のエラーを防ぐ。
 setting the tag number. 
This method shows Identification of number 
that pushed in method of action.
 And prevented two sheets of card being displayed
 by clicking one degree like a Figure 2. 


19行目(line) 
カードの枚数。 
The number of sheets of card. 

          

      図1(Figure 1)                            図2 (Figure 2)
                        
(void)loadImages {
 images = [[NSMutableArray alloc] init];
 int  i;

  for ( i = 0; i < 19; i++ )

  {    
           NSString     *str = [NSString stringWithFormat:@"img%d.png", i]; 
          [images addObject:[UIImage imageNamed:str]]; 
}


画像をファイルから読み込み、NSImageのインスタンスに格納。
 4行目、0から18までカウントアップ。
 The image is read from the file, and it stores in the instance of NSImage. 
The fourth line shows loop that does count up from 0 to 18. 


後は追加する画像のピクセルの変更、フォーマットの変更(PNGに)を行う。
 Its displayed as follows by change of the pixel
 of the added image and Format to PNG.



 見た目は変わってきた。
 次はスコア、ハイスコアの設定をやろうと思う。
 Externals have changed. 
Next, i'll try to set a score and a high score data.

2009年5月23日土曜日

プレゼン

アップルジャパンの社員が2132教室を訪れ、各自がプレゼンを行なうことになった。
本日のプレゼンを通して改めて感じたのは、目的を持つことの重要性だ。
目的とは、どのようなアプリを制作するか、テーマを決めること。
自分が何を制作するのかを決めることで、
その為に必要な知識や技術が分かるようなるし、自ずと効率も上がっていくと思う。
MatchGameで解析・拡張を納得のいくまで行うことができたら
オリジナルアプリ制作に取り組んでいきたい。

2009年5月21日木曜日

アニメーション

画像の変更は終えたので、アニメーションを追加することにした。
カードを浮かせる→実際にめくっているかのように回転させるといった
機能を付け加えたいのだが、
それなりの技術や知識が必要となるようで
今回はシンプルなアニメーションを加えることにした。
とは言っても、回転する機能は加えられたので理想に近いものはできた。

コードは以下の通り。
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
Animations:nil context:nil];
→アニメーション開始のメソッド
 [UIView setAnimationDuration:0.7];
→アニメーションの継続時間をセット
 [UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromLeftforView:selfcache:YES];
→アニメーションの遷移を指定 
if ( enabled ) 
[[UIApplication sharedApplication] sendAction:@selector(buttonPushed:)  
                     to:target from:self forEvent:event];
→もしenabledならばターゲットにアクションを送る
 [UIView commitAnimations]; 
→アニメーション終了のメソッド

このような感じのアニメーションが完成。




2009年5月19日火曜日

画像変更

現在は、中野洋一氏の
"CocoaではじめようMac/iPhoneプログラミング入門"
で制作した神経衰弱ゲームの拡張を行っている。
今回は画像の変更。

画像のサイズを変更させる為に、
Tools→ Adjust Sizeと開き、今回はピクセルを80・80に変更。
JpegをPngに変更させるため、名前を付けて保存(save as)し、フォーマットから Pingを選択する。

以下が変更後となる。
裏面は車、表面は道路標識にした。

2009年5月16日土曜日

はじめに

現在、大学のゼミでiPhoneアプリ開発の研究を行っており、
ブログという形で研究経過を載せていくことにした。

今はサンプルコードの"WhichWayIsUp"を参考にしてアプリを
横向きに表示させようとしているのですが、エラーにより表示がされない状態となっている。
今はiPhone dev centerのPDFを読み進めていこうと思う。