首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSDictionary到CGPoint

NSDictionary到CGPoint
EN

Stack Overflow用户
提问于 2012-05-24 20:49:23
回答 4查看 4.3K关注 0票数 0

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

下面是我在触摸began方法中所做的事情:

代码语言:javascript
复制
- (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..?

你知道我该怎么做吗?

任何帮助我们都会非常感谢。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-05-24 20:55:15

如果你使用的是NSValue,你可以使用CGPointValue从那里得到CGPoint

例如:

代码语言:javascript
复制
NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithCGPoint:location] forKey:@"location"];
    CGPoint points = [[touchloc valueForKey:@"location"] CGPointValue];
票数 15
EN

Stack Overflow用户

发布于 2012-05-24 20:51:50

CGPointCreateDictionaryRepresentationCGPointMakeWithDictionaryRepresentation

票数 1
EN

Stack Overflow用户

发布于 2014-09-08 17:40:01

对我来说,保存cgpoint并将cgpoint返回到nsdictionary的正确函数如下:

代码语言:javascript
复制
NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithPoint:cgPointPositionTouchPoint] forKey:@"location"];

CGPoint points = [[touchloc valueForKey:@"location"] pointValue];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10737835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档