多点触控在 cocos2d 中不起作用

发布于 2024-10-14 08:03:28 字数 1021 浏览 3 评论 0原文

这是我的 ccTouchesMoved 方法。 怎么了?我使用cocos2d框架。

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

CCNode *sprite = [self getChildByTag:kTagPlayer];
CCNode *sprite2 = [self getChildByTag:kTagEnemy];

CGPoint point;

//Собрать все касания.
NSSet *allTouches = [event allTouches];

for (UITouch *touch in allTouches)
{
    point = [touch locationInView:[touch view]];
    point = [[CCDirector sharedDirector] convertToGL:point];

    if (point.y > 384)
    {
        if (point.x > 992)
            sprite2.position = ccp(992, size.height - 100);
        else if (point.x < 32)
            sprite2.position = ccp(32, size.height - 100);
        else
            sprite2.position = ccp(point.x, size.height - 100);
    }
    else
    {
        if (point.x > 992)
            sprite.position = ccp(992, 100);
        else if (point.x < 32)
            sprite.position = ccp(32, 100);
        else
            sprite.position = ccp(point.x, 100);
    }
} 

}

This is my ccTouchesMoved method.
Whats wrong? I use cocos2d framework.

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

CCNode *sprite = [self getChildByTag:kTagPlayer];
CCNode *sprite2 = [self getChildByTag:kTagEnemy];

CGPoint point;

//Собрать все касания.
NSSet *allTouches = [event allTouches];

for (UITouch *touch in allTouches)
{
    point = [touch locationInView:[touch view]];
    point = [[CCDirector sharedDirector] convertToGL:point];

    if (point.y > 384)
    {
        if (point.x > 992)
            sprite2.position = ccp(992, size.height - 100);
        else if (point.x < 32)
            sprite2.position = ccp(32, size.height - 100);
        else
            sprite2.position = ccp(point.x, size.height - 100);
    }
    else
    {
        if (point.x > 992)
            sprite.position = ccp(992, 100);
        else if (point.x < 32)
            sprite.position = ccp(32, 100);
        else
            sprite.position = ccp(point.x, 100);
    }
} 

}

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

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

发布评论

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

评论(3

节枝 2024-10-21 08:03:28

您是否在 glView 中启用了多次触摸?默认情况下,glView 在应用程序委托中实例化。代码如下。

[glView setMultipleTouchEnabled:YES];

Have you enabled multiple touches in your glView? By default the glView is instantiated in the app delegate. The code is below.

[glView setMultipleTouchEnabled:YES];
紫瑟鸿黎 2024-10-21 08:03:28

如果您正在开发 Retina 显示应用程序,请注意所有坐标均以点为单位,而不是像素。因此,即使在 960x640 像素的 Retina 显示屏上,点坐标(触摸位置)也将在 480x320 范围内。

如果您想使用像素,请使用所有坐标的“InPixels”版本,在这种情况下:

sprite.positionInPixels = ccp(992, 100);

如果这不是问题,您应该在帖子中添加预期结果以及发生的情况。一点背景知识会有很大帮助。

In case you're developing a Retina display App, be aware that all coordinates are in points, not pixels. So even on a Retina display with 960x640 pixels the coordinates in points (your touch location) will be in the range 480x320.

If you want to use pixels, use the "InPixels" version of all coordinates, in this case:

sprite.positionInPixels = ccp(992, 100);

If that's not the problem you should add to your post what the expected outcome is and what happens instead. A little context goes a long way.

离旧人 2024-10-21 08:03:28

调试器说 allTouches 中是什么?您可以尝试像这样获取视图的所有触摸:

UITouch* touch = [touches anyObject];
NSSet* allTouches = [touches setByAddingObjectsFromSet:[event touchesForView:[touch view]]];

What does the debugger say is in allTouches? You could try getting all the touches for the view like this instead:

UITouch* touch = [touches anyObject];
NSSet* allTouches = [touches setByAddingObjectsFromSet:[event touchesForView:[touch view]]];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文