精灵套件动画与纹理滞后



我在我的精灵套件游戏中使用了纹理图集。我正在创建SKTextureAtlas对象并将其纹理存储在每个动画的数组中。因此,当我需要对我的英雄进行一些动画时,我会调用animateWithTextures向其发送相应的数组。当我开始动画时有一些滞后。有没有办法顺利开始动画?

我相信很少有方法可以解决这个问题。您需要做的是在游戏实际开始之前预加载地图集。只需在游戏开始时显示加载屏幕并预加载您的地图集即可。

你可以尝试使用 + preloadTextureAtlases:withCompletionHandler:

[SKTextureAtlas preloadTextureAtlases:textureAtlasesArray withCompletionHandler:^{ /*Game Start*/}];

在冒险游戏示例中介绍了在其他所有内容之前实现资源加载(并将所有内容保留在内存中)的另一种方法

有关异步加载资产的更多详细信息,请查看可从上面的链接下载的代码。

遇到了同样的问题,我在游戏中通过不使用地图集解决了这个问题。所以试试这个例子:

-(void)makePlayerAnimation:(SKSpriteNode *)player
{
SKTexture *texture1 = [SKTexture textureWithImageNamed:@"texture1.png"];
SKTexture *texture2 = [SKTexture textureWithImageNamed:@"texture2.png"];
SKTexture *texture3 = [SKTexture textureWithImageNamed:@"texture3.png"];

SKAction *animationTextures = [SKAction animateWithTextures:@[texture1, texture2, texture3] timePerFrame:0.1];

[player runAction:animationTextures];
}

当您希望激活动画时,请执行以下操作:

[self makePlayerAnimation:myNode];

[self makePlayerAnimation:self.myNode];

只是取决于你如何声明它。如果您需要永远运行动画,只需在上一种方法的末尾添加行:

SKAction *repeat = [SKAction repeatActionForever: animationTextures];

希望这有帮助。

最新更新