更新时间:2023-11-19 15:46:10
可能有点晚了,但我在寻找一个类似的东西。
我发现这个伟大的教程解释一切:
http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d
Probably a little bit late but I was searching for a similar thing. I found this great Tutorial which explained everything: http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
CGPoint translation = ccpSub(touchLocation, oldTouchLocation);
CGPoint newPos = ccpAdd(mySpriteToMove.position, translation);
mySpriteToMove.position = newPos;
}