This code is used by sprites on the scene so they can be dragged. I am having trouble trying to figure out how to convert this code to be compatible with the cocos2d-mac template. I appreciate any help.
////////////////////////////////////////////////////
/////properties for touches moved
- (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, oldTouchLocat开发者_StackOverflow社区ion);
[self panForTranslation:translation];
}
Add "CGPoint oldMouseLocation_;" ivar into your class.
#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
/* snip */
}
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
- (BOOL)ccMouseDragged:(NSEvent *)event {
CGPoint point = [[CCDirector sharedDirector] convertEventToGL:event];
CGPoint mouseLocation = [self convertToNodeSpace:point];
CGPoint translation = ccpSub(mouseLocation, oldMouseLocation_);
[self panForTranslation:translation];
oldMouseLocation_ = mouseLocation;
}
#endif
精彩评论