我正在使用 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;
}