0

私はiOSでのゲーム開発に不慣れです。今度は「管制飛行」「航空管制」のようなゲームを作りたいです。

ユーザーが指を使って線を引くことができ、オブジェクトがそのパスをたどる場所

だから、誰でもこのように開発するのに最適な私を導くことができます。Cocos2dそれに最適ですか?または私がこれのために使用しなければならない他のもの。

また、誰かがすでにそこにあるチュートリアルや参照リンクを知っているなら、私に提案してください。

前もって感謝します。

4

1 に答える 1

1

オブジェクトを指に追従させるには、タッチ(およびそのメソッドの1つ)を実装します。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint toPoint = [touch locationInView:self.view];
    [yourObjectOutlet setCenter:toPoint];
}

ここでは、オブジェクトの中心がパスに従いますが、オブジェクトのフレームに応じて「toPoint」を編集することで、アンカーポイントを調整できます。

編集

パスを描画する場合は、オブジェクトをそのパスに沿って移動させ、次のようにします。

//define an NSMutableArray in your header file (do not forget to alloc and init it in viewDidLoad), then:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   //you begin a new path, clear the array
   [yourPathArray removeAllObjects];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint toPoint = [touch locationInView:self.view];
    //now, save each point in order to make the path
    [yourPathArray addObject:[NSValue valueWithCGPoint:toPoint]];
}

ここで、移動を開始します。

- (IBAction)startMoving{
   [self goToPointWithIndex:[NSNumber numberWithInt:0]];
}
- (void)goToPointWithIndex:(NSNumber)indexer{
   int toIndex = [indexer intValue];  

   //extract the value from array
   CGPoint toPoint = [(NSValue *)[yourPathArray objectAtIndex:toIndex] CGPointValue];
   //you will repeat this method so make sure you do not get out of array's bounds
   if(indexer < yourPathArray.count){
       [yourObject setCenter:toPoint];
       toIndex++;
       //repeat the method with a new index
       //this method will stop repeating as soon as this "if" gets FALSE
       [self performSelector:@selector(goToPointWithIndex:) with object:[NSNumber numberWithInt:toIndex] afterDelay:0.2];
   }
}

それで全部です!

于 2012-08-20T06:17:45.890 に答える