3

COCOS2Dを使用して iPhone 向けのゲームを開発しています。

その中で、ユーザーが指をポイントから別のポイントにドラッグするときに線を引く必要があります。私の知る限りTouches Moved method、ポイントを獲得できる場所からこれを行う必要があります。

しかし、これを行う方法がわかりません。誰でもこれについて私を助けることができますか?

4

2 に答える 2

6
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event  
{
        UITouch  *theTouch = [touches anyObject];
    CGPoint touchLocation = [theTouch locationInView:[theTouch view] ];
    cgfloat x = touchLocation.x;
    cgfloat y= touchLocation.y;
printf("move x=%f,y=%f",x,y);   
}

上記のコードを試してください。touches movediPhoneでは座標点を取得します。

線を引くには、次のようなものを使用します。

-void draw
{
here is the code for line draw.
}

update メソッドでこの関数を更新します。

于 2010-12-27T13:03:16.780 に答える
6

キアオラ。退屈は、このトピックに関する答えを提供することを私に強います。

レイヤー部分 (つまり @interface GetMyTouches : CCLayer):

-(void) ccTouchesMoved:(NSSet *)inappropriateTouches withEvent:(UIEvent *)event
{
    UITouch *touchMyMinge = [inappropriateTouches anyObject];

    CGPoint currentTouchArea = [touchMyMinge locationInView:[touchMyminge view] ];
    CGPoint lastTouchArea = [touchMyMinge previousLocationInView:[touchMyMinge view]];

    // flip belly up. no one likes being entered from behind.
    currentTouchArea = [[CCDirector sharedDirector] convertToGL:currentTouchArea];
    lastTouchArea = [[CCDirector sharedDirector] convertToGL:lastTouchArea];

    // throw to console my inappropriate touches
    NSLog(@"current x=%2f,y=%2f",currentTouchArea.x, currentTouchArea.y);
    NSLog(@"last x=%2f,y=%2f",lastTouchArea.x, lastTouchArea.y);  

   // add my touches to the naughty touch array 
   naughtyTouchArray addObject:NSStringFromCGPoint(currentTouchArea)];
   naughtyTouchArray addObject:NSStringFromCGPoint(lastTouchArea)];
}

ノード部分 (つまり、@interface DrawMyTouch: CCNode) :

@implementation DrawMyTouch

-(id) init
{
    if( (self=[super init])) 
    { }
    return self;
}

-(void)draw
{
    glEnable(GL_LINE_SMOOTH);

    for(int i = 0; i < [naughtyTouchArray count]; i+=2)
    {
        start = CGPointFromString([naughtyTouchArray objectAtIndex:i]);
        end = CGPointFromString([naughtyTouchArray objectAtIndex:i+1]);

        ccDrawLine(start, end);
    }
}

@end

レイヤーパート II (つまり @interface GetMyTouches : CCLayer):

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{   
    DrawMyTouch *line = [DrawMyTouch node];
    [self addChild: line];
}

タッチは簡単です。触れているときに何をしているのかを知ることは、ロケット科学ではありません。

最後に、私が投稿した内容が理解できない場合は、ベーキングを取り上げてください。世界は、より多くのチョコレート ケーキの生産者を必要としています。

説明:

  1. カットアンドペーストから学ぶ人はいません
  2. ユーモアを見逃すなら、あなたは間違った職業に就いています

特筆すべきは、おいしいチョコレート ケーキが大好きなことです。世界は本当にもっと素晴らしいパン職人を必要としています。それは侮辱ではなく、励ましです。

「広場の外を見て、人生を生きる価値のあるものにする知識で満たされた円を見つけてください」〜Aenesidemus.

于 2011-01-09T02:22:34.117 に答える