0

私はゲームに取り組んでいます。このゲームでは、シングルタップとダブルタップでそれぞれ弾丸が発射された場合に、2つの異なるタイプを発射しようとしています。

これが私のタッチで行っている方法です。

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    for( UITouch *touch in touches ) 
    {

        CGPoint location = [touch locationInView: [touch view]];
        location = [[CCDirector sharedDirector] convertToGL: location];

        NSLog(@"TOUCH LOCATION IN TOUCH BEGAN  = (%f , %f)", location.x , location.y);

        NSUInteger tapCount = [touch tapCount];

        switch (tapCount)
        {
            case 1:
            {
                NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithCGPoint:location] forKey:@"location"];
                [self performSelector:@selector(startTimer:) withObject:touchloc afterDelay:3];
                break;
            }   
            case 2:
            {
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startTimer) object:nil];
                [self performSelector:@selector(removeBall) withObject:nil afterDelay:1];
                break;
            }

            default:
            {
                break;
            }
        }
  }

今、私の中で、perform selector(startTimer:)私が触れたポイントの座標を取得しますNSPoint(私が使用してNSDictionaryいるように)私が知りたいのは..それらのポイントをCGPointsに変換する方法です..?

どうすればいいですか?

どんな助けでも本当にありがたいです。

4

4 に答える 4

15

を使用している場合は、 を使用して元に戻すNSValueことができます。CGPointCGPointValue

例えば

NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithCGPoint:location] forKey:@"location"];
    CGPoint points = [[touchloc valueForKey:@"location"] CGPointValue];
于 2012-05-24T12:55:14.690 に答える
1

CGPointCreateDictionaryRepresentationCGPointMakeWithDictionaryRepresentation

于 2012-05-24T12:51:50.077 に答える
1

私にとって、 cgpoint を nsdictionary に保存して返すための正しい関数は次のとおりです。

NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithPoint:cgPointPositionTouchPoint] forKey:@"location"];

CGPoint points = [[touchloc valueForKey:@"location"] pointValue];
于 2014-09-08T09:40:00.663 に答える
0

ドキュメントによると、NSPoint は次のとおりです。

typedef struct _NSPoint {
    CGFloat x;
    CGFloat y;
} NSPoint;

および CGPoint は次のとおりです。

struct CGPoint {
     CGFloat x;
    CGFloat y;
};
typedef struct CGPoint CGPoint;

したがって、それらは同等の構造体であり、単純にキャストして一方から他方に変換できるはずです。どちらもオブジェクト型ではないため、辞書に直接格納することはできませんが、オブジェクトに変換するには NSValue にボックス化する必要があります。おそらく辞書から NSValue オブジェクトを取得しており、NSValue には両方の型のアクセサーがあるため、キャストせずに必要なものを直接取得できます。

CGPoint a = [somePoint CGPointValue];
NSPoint b = [somePoint pointValue];    
于 2012-05-24T13:03:45.463 に答える