有人可以帮我转换这个 cocos2d-iphone 特定代码以与 cocos2d-mac 模板兼容吗?

发布于 2024-10-20 02:10:01 字数 674 浏览 5 评论 0原文

场景中的精灵使用此代码,以便可以拖动它们。我在尝试弄清楚如何转换此代码以与 cocos2d-mac 模板兼容时遇到困难。我很感激任何帮助。

////////////////////////////////////////////////////
/////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, oldTouchLocation);    
    [self panForTranslation:translation];    
}

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, oldTouchLocation);    
    [self panForTranslation:translation];    
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的快感 2024-10-27 02:10:01

添加“CGPoint oldMouseLocation_;”伊瓦尔进入你的班级。

#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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文