在 SpriteKit 中不工作的过渡 [英] Not working transitions in SpriteKit

查看:14
本文介绍了在 SpriteKit 中不工作的过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景正在使用这样的过渡调用下一个场景:

I have a scene that is calling the next one using a transition like this:

  SKTransition *transition = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:0.5];

  SKView *skView = (SKView *)self.view;

  SKScene * scene = [[GameOverScene alloc] initWithSize:self.size];
  scene.scaleMode = SKSceneScaleModeAspectFill;
  [skView presentScene:scene transition:transition];

构成 GameOverScene 的元素(按钮、图像等)被添加到其 init 方法中.

The elements that compose GameOverScene (buttons, images, etc.) are added on its init method.

问题是没有看到过渡.一个场景立即切换到另一个场景.

The problem is that the transition is not seen. One scene immediately cuts to the other one.

我猜这个过渡发生在下一个场景有机会构建它的元素之前.我试图将下一个场景的创建移动到 didMoveToView 没有成功.

I guess that transition happens before the next scene has a chance to build its elements. I have tried to move the creation of the next scene to didMoveToView without success.

出于测试目的,我尝试将 presentScene 行延迟甚至超过 2 秒.当我这样做时,我几乎看不到过渡的结束帧.

For test purposes I have tried to delay the presentScene line in times even bigger than 2 seconds. When I do that I barely see the end frames of the transition.

我该怎么做?构建下一个场景并进行有效过渡的正确方法是什么.

How do I do that? What is the correct way of building the next scene and doing a transition that works.

推荐答案

如果新场景资源特别多,即需要大量纹理加载,则会延迟任何帧渲染.如果纹理加载花费的时间比过渡时间长,您将错过所有这些,因为将显示的第一帧在过渡完成后已经渲染.我也遇到了这个问题,尽管我能够更好地确定根本原因,因为我有 2 秒的过渡,其中只显示了最后 0.5 秒.

If the new scene is particular resource heavy, i.e., requires a lot of texture loading, that will delay any frame rendering. If the texture loading takes longer than your transition time, you will miss all of it because the first frame that will be displayed has been rendered after your transition is finished. I ran into this as well, although I was better able to determine the root cause because I had a transition of 2 seconds of which only the last 0.5 seconds were shown.

如何解决这个问题?预加载你的纹理.请参阅 苹果文档.

How to fix this? Preload your textures. See Apple Docs.

+ (void)preloadTextures:(NSArray *)textures withCompletionHandler:(void (^)(void))completionHandler

我应该强调 SKSpriteSKTexture 和您的image.png"之间的区别.SKSprite 根据其 texture 属性(或 background 颜色)和 size 绘制自己.您可以将一个 SKTexture 用于多个精灵.反过来,一个图像文件(image.png")可以提供多个 SKTexture 对象.

I should emphasize the differences between SKSprite, SKTexture and your "image.png". SKSprite draws itself based on its texture property (or background color), and size. You can use one SKTexture for many sprites. In turn, an image file ("image.png") can supply multiple SKTexture objects.

重要提示:您希望使用传递给上述方法的 SKTexture 对象数组中的纹理来实际受益于纹理加载.这需要某种形式的纹理管理.

Important: you want to use textures from the array of SKTexture objects passed to the method above to actually benefit from the texture loading. This will require some form of texture management.

如果您的问题确实与纹理有关,如果您需要我扩展纹理管理,请告诉我.可以在此处找到相关帖子(可能有点枯燥):SO sktexture-preloading.

If your problem is indeed texture related, let me know if you need me to expand on the texture management. A related post (which may be a bit dry) can be found here: SO sktexture-preloading.

这篇关于在 SpriteKit 中不工作的过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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