SpriteKit中没有工作转换 [英] Not working transitions in SpriteKit

查看:108
本文介绍了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.

如何解决这个问题?预加载纹理。请参阅 Apple Docs

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

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

我应该强调 SKSprite , SKTexture 和你的image.png。
SKSprite 根据其纹理属性(或背景 color)和 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天全站免登陆