English 中文(简体)
CGPoint 的对数
原标题:NSDictionary to CGPoint

我在做一个游戏, 我试图发射两种不同的类型, 如果子弹分别是单击和双击。

以下是我在触摸开始的方法中正在做的:

- (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;
            }
        }
  }

Now in my perform selector(startTimer:) I get the co-ordinates of point where I touch in NSPoint (As I am using NSDictionary) All I want to know is.. how we can convert those points to CGPoints.. ?

知道我该怎么做吗?

任何帮助都将受到真诚的感谢。

最佳回答

如果您正在使用 NSValue , 您可以从使用 CGPoint 返回 CGPoint

例如:

NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithCGPoint:location] forKey:@"location"];
    CGPoint points = [[touchloc valueForKey:@"location"] CGPointValue];
问题回答

CGPointCreateDlogy representation CGPointMake with difficolation CGPointMake with digpicpresentation > > > > > > > > > > > > > > > <= <= <= <= > > > > > > > > > > > 和

对于我来说,保存和返回 cgpoint 到字典的正确功能如下:

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

CGPoint points = [[touchloc valueForKey:@"location"] pointValue];

医生说NSPoint是:

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

CGPoint是:

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

所以它们可以对等结构, 您应该能够简单地投放一个转换为另一个。 也不是一个对象类型, 所以您不能直接存储在字典中, 但必须在 NSVValue 中将其框起来, 以将其转换为对象 。 您可能正在从您的字典中获取 NSVValue 对象, 而 NSVValue 有两种类型的存取器, 这样您就可以直接获得您需要的, 而无需投放的 :

CGPoint a = [somePoint CGPointValue];
NSPoint b = [somePoint pointValue];    




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签