Cocos2D 2.x - 多点触控是滞后的,但没有FPS下降

时间:2014-03-17 03:47:41

标签: ios objective-c cocos2d-iphone multi-touch cocos2d-iphone-2.x

在我的新游戏中,我必须使用cocos2d处理多点触控,同时移动两个玩家。然而,有时看起来触摸是滞后的!当我上场比赛时,一切都非常顺利,但随后我和球员们一起出现了一个无处不在的状态。运动,但其他物体移动顺利!所以我决定进行分析,一切都很好,我的游戏总是在56-60 fps之间运行,即使是"滞后"。所以我猜它不是内存,也不是FPS问题,而是更多的触摸处理问题......这是我的代码:

- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        tapCount ++;

        CGPoint location = [touch locationInView:[touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];

        //Do my stuff here...

        NSLog(@"Tap Count:%d", tapCount);
    }
}

- (void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (tapCount == 0) return;

    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInView:[touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];
        CGPoint prevLocation = [[CCDirector sharedDirector] convertToGL:[touch previousLocationInView:[touch view]]];

        float diff = (location.y - prevLocation.y) / ipadScale * SENSIVITY;

        //MOVE MY PLAYERS HERE
    }
}

- (void) ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    [self ccTouchesEnded:touches withEvent:event];
}

- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch *touch in touches) {
        tapCount--;
        NSLog(@"Tap Count:%d", tapCount);
    }

    if (tapCount <= 0) {
        tapCount = 0;
        [self pauseGame];
    }
}

我还将我的游戏场景注册为标准代表,这是问题所在吗?我想不是因为它需要多点触控! 我相信这个代码也没有任何问题,我是对的吗?当我说滞后时,它就像以25 FPS的速度跑,这不是什么大问题,但有点烦人!

请帮帮我!谢谢!

0 个答案:

没有答案