Ios 如何在cocos2d iphone的init函数中获取触摸位置?
我需要触摸坐标Ios 如何在cocos2d iphone的init函数中获取触摸位置?,ios,xcode,cocos2d-iphone,Ios,Xcode,Cocos2d Iphone,我需要触摸坐标 -(id) init{ } 但我能让他们进去 -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{ CGPoint touchLocation = [touch locationInView: [touch view]]; touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation]; tou
-(id) init{ }
但我能让他们进去
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchLocation = [touch locationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
return YES;
}
我该怎么做呢?CCTouchStart是随机调用的。也就是说,您的程序不知道用户何时要触摸屏幕。这称为异步事件
我想不出一种方法来获取调用init时屏幕上已经显示的触摸,除非你能找到一种使用CCTouchDispatcher的方法谢谢你,我做到了。现在我需要将location.x和.y从这个函数发送到init。问题是,在init完成之前,该函数不会被调用。您必须找到一种方法,从上一个场景传递触摸位置或直接访问触摸信息,您将无法使用CCTouchStart:。请看一下CCTouchDispatcher。我将其重写为CCTouchDispatcher