gpt4 book ai didi

iOS SpriteKit 动画不出现

转载 作者:行者123 更新时间:2023-11-28 18:35:56 24 4
gpt4 key购买 nike

我正在使用 TextureAtlas 中的纹理加载动画。

但是动画没有出现在屏幕上。

只有当我对纹理进行 NSLog 时,我才会出现!看起来像一个错误。

有没有人有过类似的经历?

SKTextureAtlas *atlas = [SKTextureAtlas atlasWithRetinaCorrection:spriteSheetName_];
if ([atlas.textureNames count] == 0) return;
NSArray *r = [self getSprites:WEAPON_FIREANIMATION ofDict:atlas.textureNames];
if ([r count] == 0)return;


SKSpriteNode *firstSprite = (SKSpriteNode*)[self childNodeWithName:tFIRSTSPRITE];
[firstSprite removeActionForKey:aFIRE_ANIM];

NSMutableArray *walkAnimFrames = [NSMutableArray array];
int k =0;
if (self.weaponAnimDuration == 0)
{
k = (self.weaponShootInterval / 0.1f)/[r count];
} else
{
k = (self.weaponAnimDuration / 0.1f)/[r count];
}
for (int i = 0; i<k; i++)
{
for (NSString *sname in r)
{
[walkAnimFrames addObject:[SKTexture textureWithImageNamed:sname]];
}

}
NSLog(@"%@",walkAnimFrames);

SKAction *weaponAnim = [SKAction animateWithTextures:walkAnimFrames timePerFrame:0.1f];
[firstSprite runAction:weaponAnim withKey:aFIRE_ANIM];

#import "SKTextureAtlas+MySKTextureAtlas.h"
@implementation SKTextureAtlas (MySKTextureAtlas)

+(SKTextureAtlas*)atlasWithRetinaCorrection:(NSString*)name
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00)
{
name = [NSString stringWithFormat:@"%@@2x",name];
}

NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"atlasc"];
if (path == Nil) return Nil;

return [SKTextureAtlas atlasNamed:name];
}

@implementation NSArray (Tools)


-(NSArray*)animationTextureFrames
{
NSMutableArray *rr = [NSMutableArray new];
for (NSString *name in self)
{
SKTexture *tex = [SKTexture textureWithImageNamed:name];
[rr addObject:tex];
}
return rr;
}

最佳答案

我发现了错误!

我必须预加载纹理。

 [SKTexture preloadTextures:explosionTextures withCompletionHandler:^(void){}];

关于iOS SpriteKit 动画不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19159537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com