Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在cocos2d iphone的init函数中获取触摸位置?_Ios_Xcode_Cocos2d Iphone - Fatal编程技术网

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