我正在做一个游戏,在这个游戏中,我试图发射两种不同类型的子弹,如果子弹分别在单击和双击上。
下面是我在触摸began方法中所做的事情:
- (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..?
你知道我该怎么做吗?
任何帮助我们都会非常感谢。
发布于 2012-05-24 20:55:15
如果你使用的是NSValue,你可以使用CGPointValue从那里得到CGPoint。
例如:
NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithCGPoint:location] forKey:@"location"];
CGPoint points = [[touchloc valueForKey:@"location"] CGPointValue];发布于 2012-05-24 20:51:50
CGPointCreateDictionaryRepresentation和CGPointMakeWithDictionaryRepresentation
发布于 2014-09-08 17:40:01
对我来说,保存cgpoint并将cgpoint返回到nsdictionary的正确函数如下:
NSDictionary * touchloc = [NSDictionary dictionaryWithObject:[NSValue valueWithPoint:cgPointPositionTouchPoint] forKey:@"location"];
CGPoint points = [[touchloc valueForKey:@"location"] pointValue];https://stackoverflow.com/questions/10737835
复制相似问题