开发者

Can someone help me convert this cocos2d-iphone specific code to be compatible with the cocos2d-mac template?

开发者 https://www.devze.com 2023-02-14 17:08 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消