简体   繁体   English

如何制作Spritekit动画背景?

[英]How to make animated spritekit background?

我想在游戏中制作动画空间背景,我尝试在spritekit“星星节点”上使用节点,但由于星星数量过多,游戏变得迟钝,是否有任何程序或方法可以制作高清动画背景?

You just need one node for the background ya know. 您只需要一个节点即可知道背景。

Basically, you create each frame of your animated background as images. 基本上,您将动画背景的每一帧都创建为图像。 You can put these images into an image atlas in the asset catalogue. 您可以将这些图像放入资产目录中的图像集。

Now, you can add a single sprite node that covers the whole scene as the "background". 现在,您可以添加一个覆盖整个场景的单个Sprite节点作为“背景”。 You just set the texture of the sprite node to the first frame of your animation. 您只需将精灵节点的纹理设置为动画的第一帧。

Then, in didMoveToView or some methods like that, 然后,在didMoveToView或类似的方法中,

  1. get your image atlas as an SKTextureAtlas object 将图像图集作为SKTextureAtlas对象获取
  2. get each texture in the atlas using textureNamed and put each of them into an [SKTexture] 使用textureNamed获取地图集中的每个纹理,并将每个纹理放入[SKTexture]
  3. Now you have the array, you can do something like this: 现在有了数组,您可以执行以下操作:

- --

yourBackgroundSprite.runAction(SKAction.repeatForever(
    SKAction.animateWithtextures(theTexturesYouCreatedInStep2, timePerFrame: 30)
))

This link might also help you. 此链接也可能对您有帮助。

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

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