在展示SKScene后取消隐藏UIButton时延迟? [英] Delay when unhiding UIButtons after presenting SKScene?

查看:133
本文介绍了在展示SKScene后取消隐藏UIButton时延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个我没想到的延迟/暂停,到目前为止我的理由让我摸不着头脑。我有一个简单的游戏设置,其中 UIViewController 显示了许多UIButtons [PLAY GAME] [VIEW SCORES]等,这反过来呈现了不同的 SKScene

I have encountered a delay/pause that I was not expecting and the reason so far has me scratching my head. I have a simple game setup where the UIViewController shows a number of UIButtons [PLAY GAME] [VIEW SCORES] etc. which in turn present a different SKScene

我的问题是,当我尝试将这些按钮的可见性设置为可见时(以前设置为隐藏在中)来自 UIViewController 的viewDidLoad )它们需要大约5秒钟来实际显示。

My problem is that when I try and set the visibility of these buttons to visible (perviously set to hidden in viewDidLoad) from the UIViewController they take about 5 seconds to actually show.

@implementation ViewController
- (void)presentTitleScene {

    // SHOW BUTTONS
    [[self logoLabel] setHidden:NO];
    [[self gameButton] setHidden:NO];
    [[self scoreButton] setHidden:NO];
    [[self creditsButton] setHidden:NO];

    // PRESENT SCENE
    SKScene *titleScene = [TitleScene sceneWithSize:[[self spriteKitView] bounds].size];
    [titleScene setName:@"TITLE_SCENE"];
    [titleScene setScaleMode:SKSceneScaleModeAspectFill];
    [(SKView *)[self view] presentScene:titleScene];
    [self setCurrentScene:titleScene];
}
@end

所有代码都会运行, SKScene 正确显示,然后大约5-6秒后出现按钮?有什么我可以做的(强制更新)或只是设计它或与它一起生活的情况?

What happens is all the code runs, the SKScene presents correctly, then after about 5-6 seconds the buttons appear? Is there anything I can do about this (force an update) or is it just a case of design it out or live with it?

这在模拟器和设备。

查看输出日志,您可以在调用<$ c后清楚地看到$ c> preloadTextureAtlases:withCompletionHandler:执行跳转到另一个线程。方法 preloadTextureAtlases:withCompletionHandler:在主线程上调用,它应该在后台线程上预加载textureAtlas,但我的印象是completionHandler会回调主线程,这个假设是正确的还是我错了?

Looking at the output log you can clearly see that after calling preloadTextureAtlases:withCompletionHandler: that execution jumps to another thread. The method preloadTextureAtlases:withCompletionHandler: is called on the main thread and its supposed to preload the textureAtlas(s) on a background thread, but I was under the impression that the completionHandler would call back onto the main thread, is this assumption right or am I wrong?

移至回答如下。

推荐答案

关于preloadTextureAtlases:withCompletionHandler:在后台线程上调用completionHandler,我会假设同一个那是用来预装地图集的。我遇到的问题是我使用完成处理程序将NSNotification发送到我的viewController,说资产已加载,启动游戏这个问题是通知是在发送它们的同一个线程中传递的从所以我的游戏也开始在后台线程。因此,将UIButtons设置为可见的代码也在同一个后台线程上运行,因此它们对可见或隐藏的反应有所延迟。

With regards to preloadTextureAtlases:withCompletionHandler: the completionHandler gets called on a background thread, I would assume the same one that was used to preload the atlases. The problem that I was having was that I was using the completion handler to send an NSNotification to my viewController saying "the assets have loaded, start the game" The issue with this is that "Notifications are delivered in the same thread that they are sent from" so my game also started in the background thread. As a consequence the code that set the UIButtons to visible was also running on that same background thread, hence the delay in them reacting to either being made visible or hidden.

这篇关于在展示SKScene后取消隐藏UIButton时延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆