ios – SpriteKit animateWithTextures不适用于纹理图集

ios – SpriteKit animateWithTextures不适用于纹理图集,第1张

概述当我不使用纹理图集时,一切都运行正常.但是当我使用纹理图集时,animateWithTextures不起作用而且什么都没有出现. 这是我的代码 SKTexture *spaceshipTexture = [SKTexture textureWithImageNamed:@"monkey.png"];SKSpriteNode *spaceship = [SKSpriteNode spriteNod 当我不使用纹理图集时,一切都运行正常.但是当我使用纹理图集时,animateWithTextures不起作用而且什么都没有出现.
这是我的代码

SKTexture *spaceshipTexture = [SKTexture textureWithImagenamed:@"monkey.png"];SKSpriteNode *spaceship = [SKSpriteNode spriteNodeWithTexture:spaceshipTexture];spaceship.position = CGPointMake(0,0);spaceship.anchorPoint = CGPointMake(0,0);[self addChild: spaceship];NSMutableArray *images=[NSMutableArray arrayWithCapacity:14];for (int i=1; i<=14; i++) {    Nsstring *filename=[Nsstring stringWithFormat:@"%dShuGuangx.png",i];    SKTexture *tempTexture=[SKTexture textureWithImagenamed:filename];    [images addobject:tempTexture];}NSLog(@"count %d",images.count);SKAction *walkAnimation = [SKAction animateWithTextures:images timePerFrame:0.1];[spaceship runAction:walkAnimation];
解决方法
[SKTexture preloadTextures:images withCompletionHandler:^(voID){        [spaceship runAction:walkAnimation];    }];

这解决了我的问题.

总结

以上是内存溢出为你收集整理的ios – SpriteKit animateWithTextures不适用于纹理图集全部内容,希望文章能够帮你解决ios – SpriteKit animateWithTextures不适用于纹理图集所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1071852.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存