0

在我的新游戏中,我必须使用 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 运行一样,这没什么大不了的,但有点烦人!

请帮我!谢谢!

4

0 回答 0