Spritekit手势被延迟了

时间:2016-04-19 15:55:27

标签: ios iphone sprite-kit 2d

我有一个spritekit项目,我在其中显示一个球,我可以向左/向右/向上/向下滑动,问题是从场景呈现的那一刻到实际滑动工作需要大约2秒的时刻在最初的打嗝之后它完美无缺,但每次我开始那个场景都会发生这个

在viewDidLayoutSubviews上调用一次:

-(void)addScene
{
//    viewGame.showsFPS = YES;
//    viewGame.showsNodeCount = YES;
//    viewGame.showsPhysics = YES;

    /* Sprite Kit applies additional optimizations to improve rendering performance */
    viewGame.ignoresSiblingOrder = YES;
    viewGame.allowsTransparency=YES;

    // Create and configure the scene.
    scene = [GameScene sceneWithSize:viewGame.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    scene.delegateScene = self;

    // Present the scene.
    [viewGame presentScene:scene];

    [scene initialSetup];
}

并且场景的代码确实移动到了视图:

-(void)didMoveToView:(SKView *)view
{
    // Set scene to handle the swipe gesture for each direction

    NSLog(@"didMoveToView");

    UISwipeGestureRecognizer *swipeGestureUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGestureUp.direction = UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:swipeGestureUp];

    UISwipeGestureRecognizer *swipeGestureDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGestureDown.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeGestureDown];

    UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeGestureLeft];

    UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGestureRight.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipeGestureRight];
}

我在控制台中有这些时间:

2016-04-19 18:43:45.171 GAMEX[9699:3900188] didMoveToView
2016-04-19 18:43:45.171 GAMEX[9699:3900188] initial setup start
2016-04-19 18:43:45.239 GAMEX[9699:3900188] initial setup end
2016-04-19 18:43:45.243 GAMEX[9699:3900188] <SKMetalLayer: 0x156277360>: calling -display has no effect.
2016-04-19 18:43:47.432 GAMEX[9699:3900188] handleSwipeGesture
2016-04-19 18:43:47.437 GAMEX[9699:3900188] handleSwipeGesture
2016-04-19 18:43:47.439 GAMEX[9699:3900188] handleSwipeGesture
2016-04-19 18:43:47.444 GAMEX[9699:3900188] handleSwipeGesture
2016-04-19 18:43:47.583 GAMEX[9699:3900188] handleSwipeGesture

正如你所看到的那样,初始设置需要很少,而且移动到视图,我会在应用程序显示在屏幕上时立即触摸和滑动,但是在2秒后检测到该方法,就像保持接收事件的主要线索。

如果我启用showFPS,这两秒钟显示1 fps,然后在2秒后显示60 fps。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试在addScene而不是viewDidLoad中调用您的viewDidLayoutSubviews方法。在我看到你的视图控制器和场景的整个代码之前,我无法给出更好的答案。