简体   繁体   English

如何在多个场景之间共享背景SpriteNode?

[英]How to share Background SpriteNode among Multiple Scenes?

Well, the title says it all. 好吧,标题说明了一切。 If I am currently in a presented Scene of which I have initialized a Background SpriteNode to be a class constant, then how do I use the same Background SpriteNode in my next presented scene without having to create another SpriteNode that behaves and looks exactly the same as in the previous scene. 如果我当前处于一个演示场景中,并且已将Background SpriteNode初始化为一个类常量,那么如何在下一个演示场景中使用相同的Background SpriteNode,而不必创建另一个行为与外观完全相同的SpriteNode在上一个场景中。

Will creating another SpriteNode be costly, assuming the background object loads its texture from a texture atlas? 假设背景对象从纹理图册加载其纹理,则创建另一个SpriteNode是否会很昂贵?

And, I am using Swift. 而且,我正在使用Swift。

Something like this should work. 这样的事情应该起作用。

backgroundSprite.removeFromParent()
nextScene.addChild(backgroundSprite)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM