我正在使用TextureAtlas中的纹理加载动画。
但动画没有出现在屏幕上。
我只出现在NSLog纹理中!看起来像个bug。
有人有类似的经历吗?
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;
}
答案 0 :(得分:3)
我发现了这个错误!
我必须预加载纹理。
[SKTexture preloadTextures:explosionTextures withCompletionHandler:^(void){}];
答案 1 :(得分:1)
这就是我的做法,并没有任何问题。
NSMutableArray *textures = [NSMutableArray arrayWithCapacity:5];
for (int i = 1; i < 5; i++) {
NSString *textureName = [NSString stringWithFormat:@"rocket%d", i];
SKTexture *texture = [SKTexture textureWithImageNamed:textureName];
[textures addObject:texture];
}
self.rocketAnimation = [SKAction animateWithTextures:textures timePerFrame:0.1];
// add animation to my sprite
[self.projectile runAction:[SKAction repeatActionForever:self.rocketAnimation]];
// add spite to screen etc...
[self addChild:self.projectile];
答案 2 :(得分:1)
看到这篇文章,当图像使用纹理图集时有很多透明空间时会出现错误。
答案 3 :(得分:0)
答案 4 :(得分:0)
转到您的项目并按照以下步骤操作: - 1&gt;转到Build Settings,2&gt;搜索启用纹理图集生成并选择是