0

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;
}
4

5 に答える 5

3

バグ発見!

テクスチャをプリロードする必要がありました。

 [SKTexture preloadTextures:explosionTextures withCompletionHandler:^(void){}];
于 2013-10-08T13:37:37.490 に答える
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];
于 2013-10-04T03:56:31.280 に答える
0

NSLog は、他のほとんどの操作に比べて非常に低速です。その呼び出しを挿入するだけで、アプリのメイン スレッドに大幅な一時停止が追加されます。テクスチャの読み込みがタスクを GPU に送信していると思います。NSLog 呼び出しがないと、GPU はタスクを完了するのに十分な時間がない可能性があります。たぶん、テクスチャをプリロードできます。

于 2013-10-07T16:02:37.133 に答える