0

我正在加载一个菜单,其中有 7 个层,我可以在其中滑动。在第一次加载时,刷卡在 60fps 时很流畅,但是我弹出场景并再次推送它,刷卡非常慢,尽管应用程序显示 60fps,并且 ccTouchesMoved 的调用间隔与第一次加载时大致相同。

在每一层上,我添加了一些静态 CCSprite 和一个 CCMenu。

所有项目都已解除分配,我正在 ipad 3 上测试该应用程序(因此速度不是问题)。

我认为原因更多在设置部分,并希望找到解决方案。如果有帮助,这是我的触摸方法:

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    //Swipe Detection Part 1
    firstTouch = location;

}


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

    NSSet *allTouches = [event allTouches];
    UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
    CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    CGSize winSize = [[CCDirector sharedDirector] winSize];

    for(int i=0;i<[layerList count];i++)
    {

        [[layerList objectAtIndex:i] setPosition:CGPointMake((i-currentLayer)*winSize.width + (location.x - firstTouch.x),0) ];
    }
}

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];
    UITouch * touch = [[allTouches allObjects] objectAtIndex:0];
    CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    //Swipe Detection Part 2
    lastTouch = location;

    //Swipe Detection Part 2
    lastTouch = location;

    //Minimum length of the swipe
    float swipeLength = ccpDistance(firstTouch, lastTouch);

    //Check if the swipe is a left swipe and long enough
    if (firstTouch.x > lastTouch.x && swipeLength > 60) {
        [self doStuffLeft];
    }
    else if (firstTouch.x < lastTouch.x && abs(swipeLength) > 60) {
        [self doStuffRight];
    }



}
4

1 回答 1

0

想通了,[CCDirector sharedInstance] 被暂停了。

于 2012-09-17T12:17:23.140 回答