0

誰かが私を助けてくれて、おそらく私を正しい方向に向けてくれるのではないかと思っていました。

これが私のコードです:

- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:[touch view]];
    point = [[CCDirector sharedDirector] convertToGL:point];
    sprite.position = ccp (sprite.x, point.y);
}

これが私がやろうとしていることです。

スプライトをクリックして、Y軸のみを上下にドラッグしたい。スプライトを画面の上部に近づけたいのですが、これはポートレートモードです。

別の場所で画面に触れるたびに「飛び出る」または「スキップする」のは望ましくありません。

任意のポインタをいただければ幸いです。

4

1 に答える 1

0

ベクトルを使用します。このコードサンプルは、標準の代わりにターゲットのタッチデリゲートを使用します。newPos xプロパティを常に同じにして、動作を実現します。

- (void)panForTranslation:(CGPoint)translation {    
    if (selSprite) {
        CGPoint newPos = ccpAdd(selSprite.position, translation);
        selSprite.position = newPos;
    }
}

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {       
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];

    CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
    oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
    oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];

    CGPoint translation = ccpSub(touchLocation, oldTouchLocation);    
    [self panForTranslation:translation];    
}
于 2012-07-23T15:30:36.577 に答える