ccTouchesBegan 中如何让获取的坐标是相对整个屏幕的坐标,而不是在当前view的坐标
ccTouchesBegan 中如何让获取的坐标是相对整个屏幕的坐标,而不是在当前view的坐标
在cocos2d中,在我们在CCLayer中处理 ccTouchesBegan等类似的touch事件的时候,我们一般用下面的代码来获得当前的用户点击位置:
UITouch *touch=[touches anyObject]; CGPoint touchLocation= [touch locationInView:[touch view]]; CGPoint glLocation=[[CCDirector sharedDirector] convertToGL:touchLocation]; glLocation = [self convertToNodeSpace:glLocation];
//判断是否是touch在ruler的范围内 if ( glLocation.y >= - SelBarSprite.contentSize.height * 0.5f && glLocation.y <= SelBarSprite.contentSize.height * 0.5f && glLocation.x >= - SelBarSprite.contentSize.width * 0.5f && glLocation.x <= SelBarSprite.contentSize.width * 0.5f) { bTouchInsideBlinderRuler=true; touchBeginPoint=glLocation; touchOldPoint=glLocation; }
UITouch *touch=[touches anyObject]; CGPoint touchLocation = [touch locationInView:[[CCDirector sharedDirector] view]]; CGPoint glLocation=[[CCDirector sharedDirector] convertToGL:touchLocation]; glLocation = [self convertToNodeSpace:glLocation];